jdk/src/jdk.crypto.token/share/native/libj2pkcs11/p11_sessmgmt.c
author mchung
Wed, 14 Dec 2016 10:51:13 -0800
changeset 42693 6645de32a866
parent 25859 jdk/src/jdk.crypto.pkcs11/share/native/libj2pkcs11/p11_sessmgmt.c@3317bb8137f4
permissions -rw-r--r--
8171201: Drop java.compact$N aggregator modules 8171202: Rename jdk.crypto.pkcs11 and jdk.pack200 to end with Java letters Reviewed-by: alanb, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/* Copyright  (c) 2002 Graz University of Technology. All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * Redistribution and use in  source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * modification, are permitted  provided that the following conditions are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * 1. Redistributions of  source code must retain the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *    this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * 2. Redistributions in  binary form must reproduce the above copyright notice,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *    this list of conditions and the following disclaimer in the documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *    and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 3. The end-user documentation included with the redistribution, if any, must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *    include the following acknowledgment:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *    "This product includes software developed by IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *     Technology."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *    Alternately, this acknowledgment may appear in the software itself, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *    and wherever such third-party acknowledgments normally appear.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * 4. The names "Graz University of Technology" and "IAIK of Graz University of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *    Technology" must not be used to endorse or promote products derived from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *    this software without prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * 5. Products derived from this software may not be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *    "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *    written permission of Graz University of Technology.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  POSSIBILITY  OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include "pkcs11wrapper.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include <assert.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#include "sun_security_pkcs11_wrapper_PKCS11.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/* The list of notify callback handles that are currently active and waiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * for callbacks from their sessions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
NotifyListNode *notifyListHead = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
jobject notifyListLock = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#endif /* NO_CALLBACKS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#ifdef P11_ENABLE_C_OPENSESSION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Method:    C_OpenSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * Signature: (JJLjava/lang/Object;Lsun/security/pkcs11/wrapper/CK_NOTIFY;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @param   jlong jSlotID               CK_SLOT_ID slotID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @param   jlong jFlags                CK_FLAGS flags
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @param   jobject jApplication        CK_VOID_PTR pApplication
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @param   jobject jNotify             CK_NOTIFY Notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @return  jlong jSessionHandle        CK_SESSION_HANDLE_PTR phSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1OpenSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    (JNIEnv *env, jobject obj, jlong jSlotID, jlong jFlags, jobject jApplication, jobject jNotify)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    CK_SLOT_ID ckSlotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    CK_FLAGS ckFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    CK_VOID_PTR ckpApplication;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    CK_NOTIFY ckNotify;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    jlong jSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    NotifyEncapsulation *notifyEncapsulation = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#endif /* NO_CALLBACKS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    if (ckpFunctions == NULL) { return 0L; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    ckSlotID = jLongToCKULong(jSlotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    ckFlags = jLongToCKULong(jFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    if (jNotify != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        notifyEncapsulation = (NotifyEncapsulation *) malloc(sizeof(NotifyEncapsulation));
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   100
        if (notifyEncapsulation == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   101
            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
   102
            return 0L;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   103
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        notifyEncapsulation->jApplicationData = (jApplication != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                ? (*env)->NewGlobalRef(env, jApplication)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        notifyEncapsulation->jNotifyObject = (*env)->NewGlobalRef(env, jNotify);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        ckpApplication = notifyEncapsulation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        ckNotify = (CK_NOTIFY) &notifyCallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        ckpApplication = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        ckNotify = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        ckpApplication = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        ckNotify = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#endif /* NO_CALLBACKS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    TRACE0("DEBUG: C_OpenSession");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    TRACE1(", slotID=%u", ckSlotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    TRACE1(", flags=%x", ckFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    TRACE0(" ... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    rv = (*ckpFunctions->C_OpenSession)(ckSlotID, ckFlags, ckpApplication, ckNotify, &ckSessionHandle);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   125
    if (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
   126
#ifndef NO_CALLBACKS
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   127
        if (notifyEncapsulation != 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
   128
            if (notifyEncapsulation->jApplicationData != 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
   129
                (*env)->DeleteGlobalRef(env, jApplication);
9994f4f08a59 6812738: SSL 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
            }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   131
            (*env)->DeleteGlobalRef(env, jNotify);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   132
            free(notifyEncapsulation);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   133
        }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   134
#endif /* NO_CALLBACKS */
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   135
        return 0L;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   136
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    TRACE0("got session");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    TRACE1(", SessionHandle=%u", ckSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    TRACE0(" ... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    jSessionHandle = ckULongToJLong(ckSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    if (notifyEncapsulation != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        /* store the notifyEncapsulation to enable later cleanup */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        putNotifyEntry(env, ckSessionHandle, notifyEncapsulation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
#endif /* NO_CALLBACKS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    TRACE0("FINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    return jSessionHandle ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
#ifdef P11_ENABLE_C_CLOSESESSION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * Method:    C_CloseSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CloseSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    (JNIEnv *env, jobject obj, jlong jSessionHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    NotifyEncapsulation *notifyEncapsulation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    jobject jApplicationData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
#endif /* NO_CALLBACKS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    rv = (*ckpFunctions->C_CloseSession)(ckSessionHandle);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   181
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    notifyEncapsulation = removeNotifyEntry(env, ckSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    if (notifyEncapsulation != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        /* there was a notify object used with this session, now dump the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * encapsulation object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        (*env)->DeleteGlobalRef(env, notifyEncapsulation->jNotifyObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        jApplicationData = notifyEncapsulation->jApplicationData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (jApplicationData != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            (*env)->DeleteGlobalRef(env, jApplicationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        free(notifyEncapsulation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
#endif /* NO_CALLBACKS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
#ifdef P11_ENABLE_C_CLOSEALLSESSIONS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * Method:    C_CloseAllSessions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * @param   jlong jSlotID               CK_SLOT_ID slotID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CloseAllSessions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    (JNIEnv *env, jobject obj, jlong jSlotID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    CK_SLOT_ID ckSlotID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    NotifyEncapsulation *notifyEncapsulation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    jobject jApplicationData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
#endif /* NO_CALLBACKS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    ckSlotID = jLongToCKULong(jSlotID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    rv = (*ckpFunctions->C_CloseAllSessions)(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
   226
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /* Remove all notify callback helper objects. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    while ((notifyEncapsulation = removeFirstNotifyEntry(env)) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        /* there was a notify object used with this session, now dump the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * encapsulation object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        (*env)->DeleteGlobalRef(env, notifyEncapsulation->jNotifyObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        jApplicationData = notifyEncapsulation->jApplicationData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (jApplicationData != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            (*env)->DeleteGlobalRef(env, jApplicationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        free(notifyEncapsulation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
#endif /* NO_CALLBACKS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
#ifdef P11_ENABLE_C_GETSESSIONINFO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * Method:    C_GetSessionInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * Signature: (J)Lsun/security/pkcs11/wrapper/CK_SESSION_INFO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * @return  jobject jSessionInfo        CK_SESSION_INFO_PTR pInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
JNIEXPORT jobject JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetSessionInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    (JNIEnv *env, jobject obj, jlong jSessionHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    CK_SESSION_INFO ckSessionInfo;
14414
f338be3ef659 8001579: Cleanup warnings in security native code
jzavgren
parents: 14342
diff changeset
   259
    jobject jSessionInfo=NULL;
2
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 NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    rv = (*ckpFunctions->C_GetSessionInfo)(ckSessionHandle, &ckSessionInfo);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   268
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   269
        jSessionInfo = ckSessionInfoPtrToJSessionInfo(env, &ckSessionInfo);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   270
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    return jSessionInfo ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
#ifdef P11_ENABLE_C_GETOPERATIONSTATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * Method:    C_GetOperationState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * Signature: (J)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * @return  jbyteArray jState           CK_BYTE_PTR pOperationState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 *                                      CK_ULONG_PTR pulOperationStateLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetOperationState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    (JNIEnv *env, jobject obj, jlong jSessionHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    CK_BYTE_PTR ckpState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    CK_ULONG ckStateLength;
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   291
    jbyteArray jState = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    rv = (*ckpFunctions->C_GetOperationState)(ckSessionHandle, NULL_PTR, &ckStateLength);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   300
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return NULL ; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    ckpState = (CK_BYTE_PTR) malloc(ckStateLength);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   303
    if (ckpState == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   304
        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
   305
        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
   306
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    rv = (*ckpFunctions->C_GetOperationState)(ckSessionHandle, ckpState, &ckStateLength);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   309
    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
   310
        jState = ckByteArrayToJByteArray(env, ckpState, ckStateLength);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   311
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    free(ckpState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    return jState ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
#ifdef P11_ENABLE_C_SETOPERATIONSTATE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 * Method:    C_SetOperationState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 * Signature: (J[BJJ)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 * Parametermapping:                        *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 * @param   jlong jSessionHandle            CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 * @param   jbyteArray jOperationState      CK_BYTE_PTR pOperationState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 *                                          CK_ULONG ulOperationStateLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 * @param   jlong jEncryptionKeyHandle      CK_OBJECT_HANDLE hEncryptionKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 * @param   jlong jAuthenticationKeyHandle  CK_OBJECT_HANDLE hAuthenticationKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetOperationState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jOperationState, jlong jEncryptionKeyHandle, jlong jAuthenticationKeyHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    CK_BYTE_PTR ckpState = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    CK_ULONG ckStateLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    CK_OBJECT_HANDLE ckEncryptionKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    CK_OBJECT_HANDLE ckAuthenticationKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    jByteArrayToCKByteArray(env, jOperationState, &ckpState, &ckStateLength);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   345
    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
   346
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    ckEncryptionKeyHandle = jLongToCKULong(jEncryptionKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    ckAuthenticationKeyHandle = jLongToCKULong(jAuthenticationKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    rv = (*ckpFunctions->C_SetOperationState)(ckSessionHandle, ckpState, ckStateLength, ckEncryptionKeyHandle, ckAuthenticationKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    free(ckpState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   354
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
#ifdef P11_ENABLE_C_LOGIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 * Method:    C_Login
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 * Signature: (JJ[C)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 * @param   jlong jUserType             CK_USER_TYPE userType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * @param   jcharArray jPin             CK_CHAR_PTR pPin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 *                                      CK_ULONG ulPinLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Login
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jlong jUserType, jcharArray jPin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    CK_USER_TYPE ckUserType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    CK_CHAR_PTR ckpPinArray = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    CK_ULONG ckPinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    ckUserType = jLongToCKULong(jUserType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    jCharArrayToCKCharArray(env, jPin, &ckpPinArray, &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
   384
    if ((*env)->ExceptionCheck(env)) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    rv = (*ckpFunctions->C_Login)(ckSessionHandle, ckUserType, ckpPinArray, ckPinLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    free(ckpPinArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
2180
9994f4f08a59 6812738: SSL 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
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
#ifdef P11_ENABLE_C_LOGOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
 * Method:    C_Logout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Logout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    (JNIEnv *env, jobject obj, jlong jSessionHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    rv = (*ckpFunctions->C_Logout)(ckSessionHandle);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   414
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
/* ************************************************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
/* Functions for keeping track of notify callbacks                            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
/* ************************************************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
 * Add the given notify encapsulation object to the list of active notify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
 * objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
 * If notifyEncapsulation is NULL, this function does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation *notifyEncapsulation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    NotifyListNode *currentNode, *newNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    if (notifyEncapsulation == NULL) {
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   433
        return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    newNode = (NotifyListNode *) malloc(sizeof(NotifyListNode));
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   437
    if (newNode == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   438
        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
   439
        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
   440
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    newNode->hSession = hSession;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    newNode->notifyEncapsulation = notifyEncapsulation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    newNode->next = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    (*env)->MonitorEnter(env, notifyListLock); /* synchronize access to list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    if (notifyListHead == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        /* this is the first entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        notifyListHead = newNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        /* go to the last entry; i.e. the first node which's 'next' is NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        currentNode = notifyListHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        while (currentNode->next != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            currentNode = currentNode->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        currentNode->next = newNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    (*env)->MonitorExit(env, notifyListLock); /* synchronize access to list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
 * Removes the active notifyEncapsulation object used with the given session and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
 * returns it. If there is no notifyEncapsulation active for this session, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 * function returns NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
NotifyEncapsulation * removeNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    NotifyEncapsulation *notifyEncapsulation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    NotifyListNode *currentNode, *previousNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    (*env)->MonitorEnter(env, notifyListLock); /* synchronize access to list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    if (notifyListHead == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        /* this is the first entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        notifyEncapsulation = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        /* Find the node with the wanted session handle. Also stop, when we reach
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         * the last entry; i.e. the first node which's 'next' is NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        currentNode = notifyListHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        previousNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        while ((currentNode->hSession != hSession) && (currentNode->next != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            previousNode = currentNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            currentNode = currentNode->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (currentNode->hSession == hSession) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            /* We found a entry for the wanted session, now remove it. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            if (previousNode == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                /* it's the first node */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                notifyListHead = currentNode->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                previousNode->next = currentNode->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            notifyEncapsulation = currentNode->notifyEncapsulation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            free(currentNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            /* We did not find a entry for this session */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            notifyEncapsulation = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    (*env)->MonitorExit(env, notifyListLock); /* synchronize access to list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    return notifyEncapsulation ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
 * Removes the first notifyEncapsulation object. If there is no notifyEncapsulation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
 * this function returns NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
NotifyEncapsulation * removeFirstNotifyEntry(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    NotifyEncapsulation *notifyEncapsulation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    NotifyListNode *currentNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    (*env)->MonitorEnter(env, notifyListLock); /* synchronize access to list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    if (notifyListHead == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        /* this is the first entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        notifyEncapsulation = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        /* Remove the first entry. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        currentNode = notifyListHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        notifyListHead = notifyListHead->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        notifyEncapsulation = currentNode->notifyEncapsulation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        free(currentNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    (*env)->MonitorExit(env, notifyListLock); /* synchronize access to list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    return notifyEncapsulation ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
#endif /* NO_CALLBACKS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
#ifndef NO_CALLBACKS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
/*
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14414
diff changeset
   542
 * The function handling notify callbacks. It casts the pApplication parameter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
 * back to a NotifyEncapsulation structure and retrieves the Notify object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
 * the application data from it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
 * @param hSession The session, this callback is comming from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
 * @param event The type of event that occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
 * @param pApplication The application data as passed in upon OpenSession. In
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                       this wrapper we always pass in a NotifyEncapsulation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                       object, which holds necessary information for delegating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                       the callback to the Java VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
 * @return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
CK_RV notifyCallback(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    CK_SESSION_HANDLE hSession,     /* the session's handle */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    CK_NOTIFICATION   event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    CK_VOID_PTR       pApplication  /* passed to C_OpenSession */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    NotifyEncapsulation *notifyEncapsulation;
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   561
    extern JavaVM *jvm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    jint returnValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    jlong jSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    jlong jEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    jclass ckNotifyClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    jmethodID jmethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    jthrowable pkcs11Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    jclass pkcs11ExceptionClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    jlong errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    CK_RV rv = CKR_OK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    int wasAttached = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    if (pApplication == NULL) { return rv ; } /* This should not occur in this wrapper. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    notifyEncapsulation = (NotifyEncapsulation *) pApplication;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /* Get the currently running Java VM */
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   579
    if (jvm == NULL) { return rv ; } /* there is no VM running */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /* Determine, if current thread is already attached */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    returnValue = (*jvm)->GetEnv(jvm, (void **) &env, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    if (returnValue == JNI_EDETACHED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        /* thread detached, so attach it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        wasAttached = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        returnValue = (*jvm)->AttachCurrentThread(jvm, (void **) &env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    } else if (returnValue == JNI_EVERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        /* this version of JNI is not supported, so just try to attach */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        /* we assume it was attached to ensure that this thread is not detached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         * afterwards even though it should not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        wasAttached = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        returnValue = (*jvm)->AttachCurrentThread(jvm, (void **) &env, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        /* attached */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        wasAttached = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    jSessionHandle = ckULongToJLong(hSession);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    jEvent = ckULongToJLong(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    ckNotifyClass = (*env)->FindClass(env, CLASS_NOTIFY);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   603
    if (ckNotifyClass == NULL) { return rv; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    jmethod = (*env)->GetMethodID(env, ckNotifyClass, "CK_NOTIFY", "(JJLjava/lang/Object;)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
   605
    if (jmethod == NULL) { return rv; }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   606
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    (*env)->CallVoidMethod(env, notifyEncapsulation->jNotifyObject, jmethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                         jSessionHandle, jEvent, notifyEncapsulation->jApplicationData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    /* check, if callback threw an exception */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    pkcs11Exception = (*env)->ExceptionOccurred(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    if (pkcs11Exception != NULL) {
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   614
        /* TBD: clear the pending exception with ExceptionClear? */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        /* The was an exception thrown, now we get the error-code from it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        pkcs11ExceptionClass = (*env)->FindClass(env, CLASS_PKCS11EXCEPTION);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   617
        if (pkcs11ExceptionClass == NULL) { return rv; }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   618
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        jmethod = (*env)->GetMethodID(env, pkcs11ExceptionClass, "getErrorCode", "()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
   620
        if (jmethod == NULL) { return rv; }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   621
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        errorCode = (*env)->CallLongMethod(env, pkcs11Exception, jmethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        rv = jLongToCKULong(errorCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /* if we attached this thread to the VM just for callback, we detach it now */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    if (wasAttached) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        returnValue = (*jvm)->DetachCurrentThread(jvm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    return rv ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
#endif /* NO_CALLBACKS */