jdk/src/jdk.crypto.pkcs11/share/native/libj2pkcs11/p11_keymgmt.c
author sundar
Mon, 31 Aug 2015 17:51:02 +0530
changeset 32434 769b3d81ae69
parent 25859 3317bb8137f4
child 39142 bf48a9f13cf2
permissions -rw-r--r--
8134731: Function.prototype.apply interacts incorrectly with arguments Reviewed-by: attila, hannesw
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_GENERATEKEY
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_GenerateKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;[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   jobject jMechanism          CK_MECHANISM_PTR pMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @param   jobjectArray jTemplate      CK_ATTRIBUTE_PTR pTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *                                      CK_ULONG ulCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @return  jlong jKeyHandle            CK_OBJECT_HANDLE_PTR phKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jobjectArray jTemplate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    CK_MECHANISM ckMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    CK_ULONG ckAttributesLength;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
    76
    CK_OBJECT_HANDLE ckKeyHandle = 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
    77
    jlong jKeyHandle = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    if (ckpFunctions == NULL) { return 0L; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    jMechanismToCKMechanism(env, jMechanism, &ckMechanism);
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
    85
    if ((*env)->ExceptionCheck(env)) { 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
    86
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    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
    88
    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
    89
        if (ckMechanism.pParameter != NULL_PTR) {
9994f4f08a59 6812738: SSL 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
            free(ckMechanism.pParameter);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
    91
        }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
    92
        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
    93
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    rv = (*ckpFunctions->C_GenerateKey)(ckSessionHandle, &ckMechanism, ckpAttributes, ckAttributesLength, &ckKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
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
    97
    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
    98
        jKeyHandle = ckULongToJLong(ckKeyHandle);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
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
        /* cheack, if we must give a initialization vector back to Java */
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   101
        switch (ckMechanism.mechanism) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        case CKM_PBE_MD2_DES_CBC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        case CKM_PBE_MD5_DES_CBC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        case CKM_PBE_MD5_CAST_CBC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        case CKM_PBE_MD5_CAST3_CBC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        case CKM_PBE_MD5_CAST128_CBC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        /* case CKM_PBE_MD5_CAST5_CBC:  the same as CKM_PBE_MD5_CAST128_CBC */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        case CKM_PBE_SHA1_CAST128_CBC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        /* case CKM_PBE_SHA1_CAST5_CBC: the same as CKM_PBE_SHA1_CAST128_CBC */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            /* we must copy back the initialization vector to the jMechanism object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            copyBackPBEInitializationVector(env, &ckMechanism, jMechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            break;
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
   113
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
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
   116
    if (ckMechanism.pParameter != NULL_PTR) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        free(ckMechanism.pParameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
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
   119
    freeCKAttributeArray(ckpAttributes, ckAttributesLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    return jKeyHandle ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#ifdef P11_ENABLE_C_GENERATEKEYPAIR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * Method:    C_GenerateKeyPair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)[J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * Parametermapping:                          *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * @param   jlong jSessionHandle              CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * @param   jobject jMechanism                CK_MECHANISM_PTR pMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * @param   jobjectArray jPublicKeyTemplate   CK_ATTRIBUTE_PTR pPublicKeyTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *                                            CK_ULONG ulPublicKeyAttributeCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * @param   jobjectArray jPrivateKeyTemplate  CK_ATTRIBUTE_PTR pPrivateKeyTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *                                            CK_ULONG ulPrivateKeyAttributeCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * @return  jlongArray jKeyHandles            CK_OBJECT_HANDLE_PTR phPublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *                                            CK_OBJECT_HANDLE_PTR phPublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKeyPair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     jobjectArray jPublicKeyTemplate, jobjectArray jPrivateKeyTemplate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    CK_MECHANISM ckMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    CK_ATTRIBUTE_PTR ckpPublicKeyAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    CK_ATTRIBUTE_PTR ckpPrivateKeyAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    CK_ULONG ckPublicKeyAttributesLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    CK_ULONG ckPrivateKeyAttributesLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    CK_OBJECT_HANDLE_PTR ckpPublicKeyHandle;  /* pointer to Public Key */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    CK_OBJECT_HANDLE_PTR ckpPrivateKeyHandle; /* pointer to Private Key */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    CK_OBJECT_HANDLE_PTR ckpKeyHandles;     /* pointer to array with Public and Private Key */
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   153
    jlongArray jKeyHandles = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    jMechanismToCKMechanism(env, jMechanism, &ckMechanism);
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 ((*env)->ExceptionCheck(env)) { 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
   162
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    ckpKeyHandles = (CK_OBJECT_HANDLE_PTR) malloc(2 * sizeof(CK_OBJECT_HANDLE));
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
   164
    if (ckpKeyHandles == 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
   165
        if (ckMechanism.pParameter != NULL_PTR) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   166
            free(ckMechanism.pParameter);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   167
        }
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   168
        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
   169
        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
   170
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    ckpPublicKeyHandle = ckpKeyHandles;   /* first element of array is Public Key */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    ckpPrivateKeyHandle = (ckpKeyHandles + 1);  /* second element of array is Private Key */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
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
   174
    jAttributeArrayToCKAttributeArray(env, jPublicKeyTemplate, &ckpPublicKeyAttributes, &ckPublicKeyAttributesLength);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   175
    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
   176
        if (ckMechanism.pParameter != NULL_PTR) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   177
            free(ckMechanism.pParameter);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   178
        }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   179
        free(ckpKeyHandles);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   180
        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
   181
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   182
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   183
    jAttributeArrayToCKAttributeArray(env, jPrivateKeyTemplate, &ckpPrivateKeyAttributes, &ckPrivateKeyAttributesLength);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   184
    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
   185
        if (ckMechanism.pParameter != NULL_PTR) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   186
            free(ckMechanism.pParameter);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   187
        }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   188
        free(ckpKeyHandles);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   189
        freeCKAttributeArray(ckpPublicKeyAttributes, ckPublicKeyAttributesLength);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   190
        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
   191
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   192
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    rv = (*ckpFunctions->C_GenerateKeyPair)(ckSessionHandle, &ckMechanism,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                     ckpPublicKeyAttributes, ckPublicKeyAttributesLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                     ckpPrivateKeyAttributes, ckPrivateKeyAttributesLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                     ckpPublicKeyHandle, ckpPrivateKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
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
   198
    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
   199
        jKeyHandles = ckULongArrayToJLongArray(env, ckpKeyHandles, 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    if(ckMechanism.pParameter != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        free(ckMechanism.pParameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    free(ckpKeyHandles);
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
   206
    freeCKAttributeArray(ckpPublicKeyAttributes, ckPublicKeyAttributesLength);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   207
    freeCKAttributeArray(ckpPrivateKeyAttributes, ckPrivateKeyAttributesLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    return jKeyHandles ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
#ifdef P11_ENABLE_C_WRAPKEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * Method:    C_WrapKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;JJ)[B
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * @param   jobject jMechanism          CK_MECHANISM_PTR pMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * @param   jlong jWrappingKeyHandle    CK_OBJECT_HANDLE hWrappingKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * @param   jlong jKeyHandle            CK_OBJECT_HANDLE hKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * @return  jbyteArray jWrappedKey      CK_BYTE_PTR pWrappedKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 *                                      CK_ULONG_PTR pulWrappedKeyLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1WrapKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jWrappingKeyHandle, jlong jKeyHandle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    CK_MECHANISM ckMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    CK_OBJECT_HANDLE ckWrappingKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    CK_OBJECT_HANDLE ckKeyHandle;
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
   233
    jbyteArray jWrappedKey = NULL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    CK_BYTE BUF[MAX_STACK_BUFFER_LEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    CK_BYTE_PTR ckpWrappedKey = BUF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    CK_ULONG ckWrappedKeyLength = MAX_STACK_BUFFER_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    if (ckpFunctions == NULL) { return NULL; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    jMechanismToCKMechanism(env, jMechanism, &ckMechanism);
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
   244
    if ((*env)->ExceptionCheck(env)) { 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
   245
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    ckWrappingKeyHandle = jLongToCKULong(jWrappingKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    ckKeyHandle = jLongToCKULong(jKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    if (rv == CKR_BUFFER_TOO_SMALL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        ckpWrappedKey = (CK_BYTE_PTR) malloc(ckWrappedKeyLength);
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
   252
        if (ckpWrappedKey == 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
   253
            if (ckMechanism.pParameter != NULL_PTR) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   254
                free(ckMechanism.pParameter);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   255
            }
10798
413b731e1818 7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents: 5506
diff changeset
   256
            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
   257
            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
   258
        }
9994f4f08a59 6812738: SSL 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
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        jWrappedKey = ckByteArrayToJByteArray(env, ckpWrappedKey, ckWrappedKeyLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
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
   266
    if (ckpWrappedKey != BUF) { free(ckpWrappedKey); }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   267
    if (ckMechanism.pParameter != NULL_PTR) {
9994f4f08a59 6812738: SSL 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
        free(ckMechanism.pParameter);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    return jWrappedKey ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
#ifdef P11_ENABLE_C_UNWRAPKEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * Method:    C_UnwrapKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J[B[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * @param   jobject jMechanism          CK_MECHANISM_PTR pMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * @param   jlong jUnwrappingKeyHandle  CK_OBJECT_HANDLE hUnwrappingKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * @param   jbyteArray jWrappedKey      CK_BYTE_PTR pWrappedKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 *                                      CK_ULONG_PTR pulWrappedKeyLen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * @param   jobjectArray jTemplate      CK_ATTRIBUTE_PTR pTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 *                                      CK_ULONG ulCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * @return  jlong jKeyHandle            CK_OBJECT_HANDLE_PTR phKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1UnwrapKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jUnwrappingKeyHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     jbyteArray jWrappedKey, jobjectArray jTemplate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    CK_MECHANISM ckMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    CK_OBJECT_HANDLE ckUnwrappingKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    CK_BYTE_PTR ckpWrappedKey = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    CK_ULONG ckWrappedKeyLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    CK_ULONG ckAttributesLength;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   300
    CK_OBJECT_HANDLE ckKeyHandle = 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
   301
    jlong jKeyHandle = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    if (ckpFunctions == NULL) { return 0L; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    jMechanismToCKMechanism(env, jMechanism, &ckMechanism);
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 ((*env)->ExceptionCheck(env)) { 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
   310
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    ckUnwrappingKeyHandle = jLongToCKULong(jUnwrappingKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    jByteArrayToCKByteArray(env, jWrappedKey, &ckpWrappedKey, &ckWrappedKeyLength);
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   313
    if ((*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
   314
        if (ckMechanism.pParameter != NULL_PTR) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   315
            free(ckMechanism.pParameter);
9994f4f08a59 6812738: SSL 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
        }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   317
        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
   318
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   319
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    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
   321
    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
   322
        if (ckMechanism.pParameter != NULL_PTR) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   323
            free(ckMechanism.pParameter);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   324
        }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   325
        free(ckpWrappedKey);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   326
        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
   327
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   328
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    rv = (*ckpFunctions->C_UnwrapKey)(ckSessionHandle, &ckMechanism, ckUnwrappingKeyHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                 ckpWrappedKey, ckWrappedKeyLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                 ckpAttributes, ckAttributesLength, &ckKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
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
   334
    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
   335
        jKeyHandle = ckLongToJLong(ckKeyHandle);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
#if 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
   338
        /* cheack, if we must give a initialization vector back to Java */
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   339
        if (ckMechanism.mechanism == CKM_KEY_WRAP_SET_OAEP) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   340
            /* we must copy back the unwrapped key info to the jMechanism object */
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   341
            copyBackSetUnwrappedKey(env, &ckMechanism, jMechanism);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   342
        }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   343
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
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
   346
    if (ckMechanism.pParameter != NULL_PTR) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        free(ckMechanism.pParameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
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
   349
    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
   350
    free(ckpWrappedKey);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    return jKeyHandle ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
#ifdef P11_ENABLE_C_DERIVEKEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
void freeMasterKeyDeriveParams(CK_MECHANISM_PTR ckMechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    CK_SSL3_MASTER_KEY_DERIVE_PARAMS *params = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS *) ckMechanism->pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    if (params == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    if (params->RandomInfo.pClientRandom != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        free(params->RandomInfo.pClientRandom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    if (params->RandomInfo.pServerRandom != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        free(params->RandomInfo.pServerRandom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    if (params->pVersion != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        free(params->pVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
void freeEcdh1DeriveParams(CK_MECHANISM_PTR ckMechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    CK_ECDH1_DERIVE_PARAMS *params = (CK_ECDH1_DERIVE_PARAMS *) ckMechanism->pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    if (params == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    if (params->pSharedData != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        free(params->pSharedData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    if (params->pPublicData != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        free(params->pPublicData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
 * Copy back the PRF output to Java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
void copyBackTLSPrfParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
{
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
    jclass jMechanismClass, jTLSPrfParamsClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    CK_TLS_PRF_PARAMS *ckTLSPrfParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    jobject jTLSPrfParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    CK_MECHANISM_TYPE ckMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    jlong jMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    CK_BYTE_PTR output;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    jobject jOutput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    jint jLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    jbyte* jBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /* get mechanism */
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   407
    jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   408
    if (jMechanismClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   410
    if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    ckMechanismType = jLongToCKULong(jMechanismType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    if (ckMechanismType != ckMechanism->mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        /* we do not have maching types, this should not occur */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /* get the native CK_TLS_PRF_PARAMS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    ckTLSPrfParams = (CK_TLS_PRF_PARAMS *) ckMechanism->pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    if (ckTLSPrfParams != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        /* get the Java CK_TLS_PRF_PARAMS object (pParameter) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   423
        if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        jTLSPrfParams = (*env)->GetObjectField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        /* copy back the client IV */
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   427
        jTLSPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   428
        if (jTLSPrfParamsClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        fieldID = (*env)->GetFieldID(env, jTLSPrfParamsClass, "pOutput", "[B");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   430
        if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        jOutput = (*env)->GetObjectField(env, jTLSPrfParams, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        output = ckTLSPrfParams->pOutput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        // Note: we assume that the token returned exactly as many bytes as we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        // requested. Anything else would not make sense.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (jOutput != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            jLength = (*env)->GetArrayLength(env, jOutput);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            jBytes = (*env)->GetByteArrayElements(env, jOutput, 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
   439
            if (jBytes == NULL) { 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
            /* copy the bytes to the Java buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            for (i=0; i < jLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                jBytes[i] = ckByteToJByte(output[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            /* copy back the Java buffer to the object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            (*env)->ReleaseByteArrayElements(env, jOutput, jBytes, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        // free malloc'd data
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
   450
        free(ckTLSPrfParams->pSeed);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   451
        free(ckTLSPrfParams->pLabel);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   452
        free(ckTLSPrfParams->pulOutputLen);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   453
        free(ckTLSPrfParams->pOutput);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
 * Class:     sun_security_pkcs11_wrapper_PKCS11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
 * Method:    C_DeriveKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
 * Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
 * Parametermapping:                    *PKCS11*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
 * @param   jlong jSessionHandle        CK_SESSION_HANDLE hSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
 * @param   jobject jMechanism          CK_MECHANISM_PTR pMechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
 * @param   jlong jBaseKeyHandle        CK_OBJECT_HANDLE hBaseKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
 * @param   jobjectArray jTemplate      CK_ATTRIBUTE_PTR pTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
 *                                      CK_ULONG ulCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
 * @return  jlong jKeyHandle            CK_OBJECT_HANDLE_PTR phKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    (JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jBaseKeyHandle, jobjectArray jTemplate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    CK_SESSION_HANDLE ckSessionHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    CK_MECHANISM ckMechanism;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    CK_OBJECT_HANDLE ckBaseKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    CK_ULONG ckAttributesLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    CK_OBJECT_HANDLE ckKeyHandle = 0;
3321
fed33393bc52 6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents: 2180
diff changeset
   478
    jlong jKeyHandle = 0L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    CK_RV rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    CK_OBJECT_HANDLE_PTR phKey = &ckKeyHandle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    if (ckpFunctions == NULL) { return 0L; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    ckSessionHandle = jLongToCKULong(jSessionHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    jMechanismToCKMechanism(env, jMechanism, &ckMechanism);
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
   487
    if ((*env)->ExceptionCheck(env)) { 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
   488
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    ckBaseKeyHandle = jLongToCKULong(jBaseKeyHandle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    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
   491
    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
   492
        if (ckMechanism.pParameter != NULL_PTR) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   493
            free(ckMechanism.pParameter);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   494
        }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   495
        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
   496
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    switch (ckMechanism.mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    case CKM_SSL3_KEY_AND_MAC_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    case CKM_TLS_KEY_AND_MAC_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    case CKM_TLS_PRF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        // these mechanism do not return a key handle via phKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        // set to NULL in case pedantic implementations check for it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        phKey = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    rv = (*ckpFunctions->C_DeriveKey)(ckSessionHandle, &ckMechanism, ckBaseKeyHandle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                 ckpAttributes, ckAttributesLength, phKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    jKeyHandle = ckLongToJLong(ckKeyHandle);
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
   515
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   516
    freeCKAttributeArray(ckpAttributes, ckAttributesLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    switch (ckMechanism.mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    case CKM_SSL3_MASTER_KEY_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    case CKM_TLS_MASTER_KEY_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        /* we must copy back the client version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        copyBackClientVersion(env, &ckMechanism, jMechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        freeMasterKeyDeriveParams(&ckMechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    case CKM_SSL3_MASTER_KEY_DERIVE_DH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    case CKM_TLS_MASTER_KEY_DERIVE_DH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        freeMasterKeyDeriveParams(&ckMechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    case CKM_SSL3_KEY_AND_MAC_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    case CKM_TLS_KEY_AND_MAC_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        /* we must copy back the unwrapped key info to the jMechanism object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        copyBackSSLKeyMatParams(env, &ckMechanism, jMechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    case CKM_TLS_PRF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        copyBackTLSPrfParams(env, &ckMechanism, jMechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    case CKM_ECDH1_DERIVE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        freeEcdh1DeriveParams(&ckMechanism);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   545
    if (ckMechanism.pParameter != NULL_PTR) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        free(ckMechanism.pParameter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   548
    if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return 0L ; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    return jKeyHandle ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
 * Copy back the client version information from the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
 * structure to the Java object. This is only used for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
 * CKM_SSL3_MASTER_KEY_DERIVE mechanism when used for deriving a key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
void copyBackClientVersion(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
{
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   561
  jclass jMechanismClass, jSSL3MasterKeyDeriveParamsClass, jVersionClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
  CK_SSL3_MASTER_KEY_DERIVE_PARAMS *ckSSL3MasterKeyDeriveParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
  CK_VERSION *ckVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
  jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
  CK_MECHANISM_TYPE ckMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
  jlong jMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
  jobject jSSL3MasterKeyDeriveParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
  jobject jVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
  /* get mechanism */
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   571
  jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   572
  if (jMechanismClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
  fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   574
  if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
  jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
  ckMechanismType = jLongToCKULong(jMechanismType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
  if (ckMechanismType != ckMechanism->mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /* we do not have maching types, this should not occur */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
  /* get the native CK_SSL3_MASTER_KEY_DERIVE_PARAMS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
  ckSSL3MasterKeyDeriveParams = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS *) ckMechanism->pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
  if (ckSSL3MasterKeyDeriveParams != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    /* get the native CK_VERSION */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    ckVersion = ckSSL3MasterKeyDeriveParams->pVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    if (ckVersion != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
      /* get the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS (pParameter) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
      fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   590
      if (fieldID == NULL) { 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
   591
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
      jSSL3MasterKeyDeriveParams = (*env)->GetObjectField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
      /* get the Java CK_VERSION */
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
   595
      jSSL3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   596
      if (jSSL3MasterKeyDeriveParamsClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
      fieldID = (*env)->GetFieldID(env, jSSL3MasterKeyDeriveParamsClass, "pVersion", "L"CLASS_VERSION";");
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
   598
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
      jVersion = (*env)->GetObjectField(env, jSSL3MasterKeyDeriveParams, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
      /* now copy back the version from the native structure to the Java structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
      /* copy back the major version */
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
   604
      jVersionClass = (*env)->FindClass(env, CLASS_VERSION);
9994f4f08a59 6812738: SSL 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 (jVersionClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
      fieldID = (*env)->GetFieldID(env, jVersionClass, "major", "B");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   607
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
      (*env)->SetByteField(env, jVersion, fieldID, ckByteToJByte(ckVersion->major));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
      /* copy back the minor version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
      fieldID = (*env)->GetFieldID(env, jVersionClass, "minor", "B");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   612
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
      (*env)->SetByteField(env, jVersion, fieldID, ckByteToJByte(ckVersion->minor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
 * Copy back the derived keys and initialization vectors from the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
 * structure to the Java object. This is only used for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
 * CKM_SSL3_KEY_AND_MAC_DERIVE mechanism when used for deriving a key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
void copyBackSSLKeyMatParams(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
{
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
   627
  jclass jMechanismClass, jSSL3KeyMatParamsClass, jSSL3KeyMatOutClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
  CK_SSL3_KEY_MAT_PARAMS *ckSSL3KeyMatParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
  CK_SSL3_KEY_MAT_OUT *ckSSL3KeyMatOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
  jfieldID fieldID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
  CK_MECHANISM_TYPE ckMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
  jlong jMechanismType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
  CK_BYTE_PTR iv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
  jobject jSSL3KeyMatParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
  jobject jSSL3KeyMatOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
  jobject jIV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
  jint jLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
  jbyte* jBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
  /* get mechanism */
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   642
  jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   643
  if (jMechanismClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
  fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   645
  if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
  jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
  ckMechanismType = jLongToCKULong(jMechanismType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
  if (ckMechanismType != ckMechanism->mechanism) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    /* we do not have maching types, this should not occur */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
  /* get the native CK_SSL3_KEY_MAT_PARAMS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
  ckSSL3KeyMatParam = (CK_SSL3_KEY_MAT_PARAMS *) ckMechanism->pParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
  if (ckSSL3KeyMatParam != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    // free malloc'd data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    if (ckSSL3KeyMatParam->RandomInfo.pClientRandom != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        free(ckSSL3KeyMatParam->RandomInfo.pClientRandom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    if (ckSSL3KeyMatParam->RandomInfo.pServerRandom != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        free(ckSSL3KeyMatParam->RandomInfo.pServerRandom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /* get the native CK_SSL3_KEY_MAT_OUT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    ckSSL3KeyMatOut = ckSSL3KeyMatParam->pReturnedKeyMaterial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    if (ckSSL3KeyMatOut != NULL_PTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
      /* get the Java CK_SSL3_KEY_MAT_PARAMS (pParameter) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
      fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   669
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
      jSSL3KeyMatParam = (*env)->GetObjectField(env, jMechanism, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
      /* get the Java CK_SSL3_KEY_MAT_OUT */
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
   673
      jSSL3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   674
      if (jSSL3KeyMatParamsClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
      fieldID = (*env)->GetFieldID(env, jSSL3KeyMatParamsClass, "pReturnedKeyMaterial", "L"CLASS_SSL3_KEY_MAT_OUT";");
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
   676
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
      jSSL3KeyMatOut = (*env)->GetObjectField(env, jSSL3KeyMatParam, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
      /* now copy back all the key handles and the initialization vectors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
      /* copy back client MAC secret handle */
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
   681
      jSSL3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   682
      if (jSSL3KeyMatOutClass == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
      fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hClientMacSecret", "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
   684
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
      (*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hClientMacSecret));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
      /* copy back server MAC secret handle */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
      fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hServerMacSecret", "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
   689
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
      (*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hServerMacSecret));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
      /* copy back client secret key handle */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
      fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hClientKey", "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
   694
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
      (*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hClientKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
      /* copy back server secret key handle */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
      fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "hServerKey", "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
   699
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
      (*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hServerKey));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
      /* copy back the client IV */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
      fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "pIVClient", "[B");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   704
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
      jIV = (*env)->GetObjectField(env, jSSL3KeyMatOut, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
      iv = ckSSL3KeyMatOut->pIVClient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
      if (jIV != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        jLength = (*env)->GetArrayLength(env, jIV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        jBytes = (*env)->GetByteArrayElements(env, jIV, 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
   711
        if (jBytes == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        /* copy the bytes to the Java buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        for (i=0; i < jLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
          jBytes[i] = ckByteToJByte(iv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        /* copy back the Java buffer to the object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        (*env)->ReleaseByteArrayElements(env, jIV, jBytes, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
      }
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
   719
      // free malloc'd data
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   720
      free(ckSSL3KeyMatOut->pIVClient);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
      /* copy back the server IV */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
      fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, "pIVServer", "[B");
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   724
      if (fieldID == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
      jIV = (*env)->GetObjectField(env, jSSL3KeyMatOut, fieldID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
      iv = ckSSL3KeyMatOut->pIVServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
      if (jIV != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        jLength = (*env)->GetArrayLength(env, jIV);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        jBytes = (*env)->GetByteArrayElements(env, jIV, 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
   731
        if (jBytes == NULL) { return; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        /* copy the bytes to the Java buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        for (i=0; i < jLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
          jBytes[i] = ckByteToJByte(iv[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        /* copy back the Java buffer to the object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        (*env)->ReleaseByteArrayElements(env, jIV, jBytes, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
      // free malloc'd data
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
   740
      free(ckSSL3KeyMatOut->pIVServer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
      free(ckSSL3KeyMatOut);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
#endif