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