jdk/src/jdk.crypto.token/share/native/libj2pkcs11/p11_objmgmt.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_objmgmt.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
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10798
diff changeset
     2
 * Copyright (c) 2003, 2011, 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
#ifdef P11_ENABLE_C_CREATEOBJECT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Method:    C_CreateObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Signature: (J[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @param   jobjectArray jTemplate      CK_ATTRIBUTE_PTR pTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *                                      CK_ULONG ulCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @return  jlong jObjectHandle         CK_OBJECT_HANDLE_PTR phObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CreateObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobjectArray jTemplate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    CK_OBJECT_HANDLE ckObjectHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    CK_ULONG ckAttributesLength;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
    75
    jlong jObjectHandle = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    if (ckpFunctions == NULL) { return 0L; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength);
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
    83
    if ((*env)->ExceptionCheck(env)) { return 0L; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    rv = (*ckpFunctions->C_CreateObject)(ckSessionHandle, ckpAttributes, ckAttributesLength, &ckObjectHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    jObjectHandle = ckULongToJLong(ckObjectHandle);
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
    88
    freeCKAttributeArray(ckpAttributes, ckAttributesLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
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
    90
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    return jObjectHandle ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#ifdef P11_ENABLE_C_COPYOBJECT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * Method:    C_CopyObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * Signature: (JJ[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @param   jlong jObjectHandle         CK_OBJECT_HANDLE hObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @param   jobjectArray jTemplate      CK_ATTRIBUTE_PTR pTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *                                      CK_ULONG ulCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * @return  jlong jNewObjectHandle      CK_OBJECT_HANDLE_PTR phNewObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1CopyObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jlong jObjectHandle, jobjectArray jTemplate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    CK_OBJECT_HANDLE ckObjectHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    CK_OBJECT_HANDLE ckNewObjectHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    CK_ULONG ckAttributesLength;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   116
    jlong jNewObjectHandle = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    if (ckpFunctions == NULL) { return 0L; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    ckObjectHandle = jLongToCKULong(jObjectHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength);
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 ((*env)->ExceptionCheck(env)) { return 0L; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    rv = (*ckpFunctions->C_CopyObject)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength, &ckNewObjectHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    jNewObjectHandle = ckULongToJLong(ckNewObjectHandle);
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
    freeCKAttributeArray(ckpAttributes, ckAttributesLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    return jNewObjectHandle ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
#ifdef P11_ENABLE_C_DESTROYOBJECT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * Method:    C_DestroyObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * Signature: (JJ)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * @param   jlong jObjectHandle         CK_OBJECT_HANDLE hObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DestroyObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jlong jObjectHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    CK_OBJECT_HANDLE ckObjectHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    ckObjectHandle = jLongToCKULong(jObjectHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    rv = (*ckpFunctions->C_DestroyObject)(ckSessionHandle, ckObjectHandle);
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
   161
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
#ifdef P11_ENABLE_C_GETOBJECTSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * Method:    C_GetObjectSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * Signature: (JJ)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * @param   jlong jObjectHandle         CK_OBJECT_HANDLE hObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * @return  jlong jObjectSize           CK_ULONG_PTR pulSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GetObjectSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jlong jObjectHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    CK_OBJECT_HANDLE ckObjectHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    CK_ULONG ckObjectSize;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   181
    jlong jObjectSize = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    if (ckpFunctions == NULL) { return 0L; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    ckObjectHandle = jLongToCKULong(jObjectHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    rv = (*ckpFunctions->C_GetObjectSize)(ckSessionHandle, ckObjectHandle, &ckObjectSize);
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
   191
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    jObjectSize = ckULongToJLong(ckObjectSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    return jObjectSize ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
#ifdef P11_ENABLE_C_GETATTRIBUTEVALUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * Method:    C_GetAttributeValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * Signature: (JJ[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * @param   jlong jObjectHandle         CK_OBJECT_HANDLE hObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * @param   jobjectArray jTemplate      CK_ATTRIBUTE_PTR pTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *                                      CK_ULONG ulCount
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_1GetAttributeValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jlong jObjectHandle, jobjectArray jTemplate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    CK_OBJECT_HANDLE ckObjectHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    CK_ULONG ckAttributesLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    CK_ULONG ckBufferLength;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   218
    CK_ULONG i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    jobject jAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    TRACE0("DEBUG: C_GetAttributeValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    TRACE1(", hSession=%u", jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    TRACE1(", hObject=%u", jObjectHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    TRACE1(", pTemplate=%p", jTemplate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    TRACE0(" ... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    ckObjectHandle = jLongToCKULong(jObjectHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    TRACE1("jAttributeArrayToCKAttributeArray now with jTemplate = %d", jTemplate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength);
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
   235
    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
   236
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    TRACE2("DEBUG: jAttributeArrayToCKAttributeArray finished with ckpAttribute = %d, Length = %d\n", ckpAttributes, ckAttributesLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /* first set all pValue to NULL, to get the needed buffer length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    for(i = 0; i < ckAttributesLength; i++) {
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
   241
        if (ckpAttributes[i].pValue != NULL_PTR) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            free(ckpAttributes[i].pValue);
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
   243
            ckpAttributes[i].pValue = NULL_PTR;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
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
   246
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    rv = (*ckpFunctions->C_GetAttributeValue)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength);
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
   248
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        free(ckpAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /* now, the ulValueLength field of each attribute should hold the exact buffer length needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * allocate the needed buffers accordingly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    for (i = 0; i < ckAttributesLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        ckBufferLength = sizeof(CK_BYTE) * ckpAttributes[i].ulValueLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        ckpAttributes[i].pValue = (void *) malloc(ckBufferLength);
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
   259
        if (ckpAttributes[i].pValue == 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
   260
            freeCKAttributeArray(ckpAttributes, i);
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   261
            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
   262
            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
   263
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        ckpAttributes[i].ulValueLen = ckBufferLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /* now get the attributes with all values */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    rv = (*ckpFunctions->C_GetAttributeValue)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
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
   270
    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
   271
        /* copy back the values to the Java attributes */
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   272
        for (i = 0; i < ckAttributesLength; i++) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   273
            jAttribute = ckAttributePtrToJAttribute(env, &(ckpAttributes[i]));
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   274
            if (jAttribute == 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
   275
                freeCKAttributeArray(ckpAttributes, ckAttributesLength);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   276
                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
   277
            }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   278
            (*env)->SetObjectArrayElement(env, jTemplate, i, jAttribute);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   279
            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
   280
                freeCKAttributeArray(ckpAttributes, ckAttributesLength);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   281
                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
   282
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
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
   285
    freeCKAttributeArray(ckpAttributes, ckAttributesLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    TRACE0("FINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
#ifdef P11_ENABLE_C_SETATTRIBUTEVALUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * Method:    C_SetAttributeValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * Signature: (JJ[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * @param   jlong jObjectHandle         CK_OBJECT_HANDLE hObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * @param   jobjectArray jTemplate      CK_ATTRIBUTE_PTR pTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 *                                      CK_ULONG ulCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SetAttributeValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jlong jObjectHandle, jobjectArray jTemplate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    CK_OBJECT_HANDLE ckObjectHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    CK_ULONG ckAttributesLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    ckObjectHandle = jLongToCKULong(jObjectHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength);
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
   316
    if ((*env)->ExceptionCheck(env)) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    rv = (*ckpFunctions->C_SetAttributeValue)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
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
    freeCKAttributeArray(ckpAttributes, ckAttributesLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
#ifdef P11_ENABLE_C_FINDOBJECTSINIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 * Method:    C_FindObjectsInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 * Signature: (J[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 * @param   jobjectArray jTemplate      CK_ATTRIBUTE_PTR pTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
 *                                      CK_ULONG ulCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObjectsInit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobjectArray jTemplate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    CK_ULONG ckAttributesLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    TRACE0("DEBUG: C_FindObjectsInit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    TRACE1(", hSession=%u", jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    TRACE1(", pTemplate=%p", jTemplate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    TRACE0(" ... ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    jAttributeArrayToCKAttributeArray(env, jTemplate, &ckpAttributes, &ckAttributesLength);
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 ((*env)->ExceptionCheck(env)) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    rv = (*ckpFunctions->C_FindObjectsInit)(ckSessionHandle, ckpAttributes, ckAttributesLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   358
    freeCKAttributeArray(ckpAttributes, ckAttributesLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    TRACE0("FINISHED\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
#ifdef P11_ENABLE_C_FINDOBJECTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 * Method:    C_FindObjects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 * Signature: (JJ)[J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
 * Parametermapping:                        *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
 * @param   jlong jSessionHandle            CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
 * @param   jlong jMaxObjectCount           CK_ULONG ulMaxObjectCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
 * @return  jlongArray jObjectHandleArray   CK_OBJECT_HANDLE_PTR phObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
 *                                          CK_ULONG_PTR pulObjectCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObjects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jlong jMaxObjectCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    CK_ULONG ckMaxObjectLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    CK_OBJECT_HANDLE_PTR ckpObjectHandleArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    CK_ULONG ckActualObjectCount;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   384
    jlongArray jObjectHandleArray = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    ckMaxObjectLength = jLongToCKULong(jMaxObjectCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    ckpObjectHandleArray = (CK_OBJECT_HANDLE_PTR) malloc(sizeof(CK_OBJECT_HANDLE) * ckMaxObjectLength);
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
   392
    if (ckpObjectHandleArray == NULL) {
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   393
        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
   394
        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
   395
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    rv = (*ckpFunctions->C_FindObjects)(ckSessionHandle, ckpObjectHandleArray, ckMaxObjectLength, &ckActualObjectCount);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   398
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   399
        jObjectHandleArray = ckULongArrayToJLongArray(env, ckpObjectHandleArray, ckActualObjectCount);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   400
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    free(ckpObjectHandleArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    return jObjectHandleArray ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
#ifdef P11_ENABLE_C_FINDOBJECTSFINAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
 * Method:    C_FindObjectsFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
 * Signature: (J)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1FindObjectsFinal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    (JNIEnv *env, jobject obj, jlong jSessionHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    if (ckpFunctions == NULL) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    rv = (*ckpFunctions->C_FindObjectsFinal)(ckSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
#endif