author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57737 | 6bbb4af131e3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
*/ |
4 |
||
5 |
/* Copyright (c) 2002 Graz University of Technology. All rights reserved. |
|
6 |
* |
|
7 |
* Redistribution and use in source and binary forms, with or without |
|
8 |
* modification, are permitted provided that the following conditions are met: |
|
9 |
* |
|
10 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
11 |
* this list of conditions and the following disclaimer. |
|
12 |
* |
|
13 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
14 |
* this list of conditions and the following disclaimer in the documentation |
|
15 |
* and/or other materials provided with the distribution. |
|
16 |
* |
|
17 |
* 3. The end-user documentation included with the redistribution, if any, must |
|
18 |
* include the following acknowledgment: |
|
19 |
* |
|
20 |
* "This product includes software developed by IAIK of Graz University of |
|
21 |
* Technology." |
|
22 |
* |
|
23 |
* Alternately, this acknowledgment may appear in the software itself, if |
|
24 |
* and wherever such third-party acknowledgments normally appear. |
|
25 |
* |
|
26 |
* 4. The names "Graz University of Technology" and "IAIK of Graz University of |
|
27 |
* Technology" must not be used to endorse or promote products derived from |
|
28 |
* this software without prior written permission. |
|
29 |
* |
|
30 |
* 5. Products derived from this software may not be called |
|
31 |
* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior |
|
32 |
* written permission of Graz University of Technology. |
|
33 |
* |
|
34 |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
|
35 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
36 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
37 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE |
|
38 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
39 |
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
40 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
|
41 |
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
|
42 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
43 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
44 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
45 |
* POSSIBILITY OF SUCH DAMAGE. |
|
46 |
*/ |
|
47 |
||
48 |
#include "pkcs11wrapper.h" |
|
49 |
||
50 |
#include <stdio.h> |
|
51 |
#include <stdlib.h> |
|
52 |
#include <string.h> |
|
53 |
#include <assert.h> |
|
54 |
||
55 |
#include "sun_security_pkcs11_wrapper_PKCS11.h" |
|
56 |
||
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
57 |
#ifdef P11_ENABLE_GETNATIVEKEYINFO |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
58 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
59 |
#define CK_ATTRIBUTES_TEMPLATE_LENGTH (CK_ULONG)61U |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
60 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
61 |
static CK_ATTRIBUTE ckpAttributesTemplate[CK_ATTRIBUTES_TEMPLATE_LENGTH] = { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
62 |
{CKA_CLASS, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
63 |
{CKA_TOKEN, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
64 |
{CKA_PRIVATE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
65 |
{CKA_LABEL, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
66 |
{CKA_APPLICATION, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
67 |
{CKA_VALUE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
68 |
{CKA_OBJECT_ID, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
69 |
{CKA_CERTIFICATE_TYPE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
70 |
{CKA_ISSUER, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
71 |
{CKA_SERIAL_NUMBER, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
72 |
{CKA_AC_ISSUER, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
73 |
{CKA_OWNER, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
74 |
{CKA_ATTR_TYPES, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
75 |
{CKA_TRUSTED, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
76 |
{CKA_KEY_TYPE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
77 |
{CKA_SUBJECT, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
78 |
{CKA_ID, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
79 |
{CKA_SENSITIVE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
80 |
{CKA_ENCRYPT, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
81 |
{CKA_DECRYPT, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
82 |
{CKA_WRAP, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
83 |
{CKA_UNWRAP, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
84 |
{CKA_SIGN, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
85 |
{CKA_SIGN_RECOVER, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
86 |
{CKA_VERIFY, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
87 |
{CKA_VERIFY_RECOVER, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
88 |
{CKA_DERIVE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
89 |
{CKA_START_DATE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
90 |
{CKA_END_DATE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
91 |
{CKA_MODULUS, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
92 |
{CKA_MODULUS_BITS, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
93 |
{CKA_PUBLIC_EXPONENT, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
94 |
{CKA_PRIVATE_EXPONENT, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
95 |
{CKA_PRIME_1, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
96 |
{CKA_PRIME_2, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
97 |
{CKA_EXPONENT_1, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
98 |
{CKA_EXPONENT_2, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
99 |
{CKA_COEFFICIENT, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
100 |
{CKA_PRIME, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
101 |
{CKA_SUBPRIME, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
102 |
{CKA_BASE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
103 |
{CKA_PRIME_BITS, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
104 |
{CKA_SUB_PRIME_BITS, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
105 |
{CKA_VALUE_BITS, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
106 |
{CKA_VALUE_LEN, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
107 |
{CKA_EXTRACTABLE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
108 |
{CKA_LOCAL, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
109 |
{CKA_NEVER_EXTRACTABLE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
110 |
{CKA_ALWAYS_SENSITIVE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
111 |
{CKA_KEY_GEN_MECHANISM, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
112 |
{CKA_MODIFIABLE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
113 |
{CKA_ECDSA_PARAMS, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
114 |
{CKA_EC_PARAMS, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
115 |
{CKA_EC_POINT, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
116 |
{CKA_SECONDARY_AUTH, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
117 |
{CKA_AUTH_PIN_FLAGS, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
118 |
{CKA_HW_FEATURE_TYPE, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
119 |
{CKA_RESET_ON_INIT, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
120 |
{CKA_HAS_RESET, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
121 |
{CKA_VENDOR_DEFINED, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
122 |
{CKA_NETSCAPE_DB, 0, 0}, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
123 |
}; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
124 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
125 |
/* |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
126 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
127 |
* Method: getNativeKeyInfo |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
128 |
* Signature: (JJJLsun/security/pkcs11/wrapper/CK_MECHANISM;)[B |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
129 |
* Parametermapping: *PKCS11* |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
130 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
131 |
* @param jlong jKeyHandle CK_OBJECT_HANDLE hObject |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
132 |
* @param jlong jWrappingKeyHandle CK_OBJECT_HANDLE hObject |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
133 |
* @param jobject jWrappingMech CK_MECHANISM_PTR pMechanism |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
134 |
* @return jbyteArray jNativeKeyInfo - |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
135 |
*/ |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
136 |
JNIEXPORT jbyteArray JNICALL |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
137 |
Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
138 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jlong jKeyHandle, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
139 |
jlong jWrappingKeyHandle, jobject jWrappingMech) |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
140 |
{ |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
141 |
jbyteArray returnValue = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
142 |
CK_SESSION_HANDLE ckSessionHandle = jLongToCKULong(jSessionHandle); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
143 |
CK_OBJECT_HANDLE ckObjectHandle = jLongToCKULong(jKeyHandle); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
144 |
CK_ATTRIBUTE_PTR ckpAttributes = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
145 |
CK_RV rv; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
146 |
jbyteArray nativeKeyInfoArray = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
147 |
jbyteArray nativeKeyInfoWrappedKeyArray = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
148 |
jbyte* nativeKeyInfoArrayRaw = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
149 |
jbyte* nativeKeyInfoWrappedKeyArrayRaw = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
150 |
unsigned int sensitiveAttributePosition = (unsigned int)-1; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
151 |
unsigned int i = 0U; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
152 |
unsigned long totalDataSize = 0UL, attributesCount = 0UL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
153 |
unsigned long totalCkAttributesSize = 0UL, totalNativeKeyInfoArraySize = 0UL; |
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
154 |
jbyte* wrappedKeySizePtr = NULL; |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
155 |
jbyte* nativeKeyInfoArrayRawCkAttributes = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
156 |
jbyte* nativeKeyInfoArrayRawCkAttributesPtr = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
157 |
jbyte* nativeKeyInfoArrayRawDataPtr = NULL; |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
158 |
CK_MECHANISM_PTR ckpMechanism = NULL; |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
159 |
char iv[16] = {0x0}; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
160 |
CK_ULONG ckWrappedKeyLength = 0U; |
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
161 |
jbyte* wrappedKeySizeWrappedKeyArrayPtr = NULL; |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
162 |
CK_BYTE_PTR wrappedKeyBufferPtr = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
163 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
164 |
CK_OBJECT_CLASS class; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
165 |
CK_KEY_TYPE keyType; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
166 |
CK_BBOOL sensitive; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
167 |
CK_BBOOL netscapeAttributeValueNeeded = CK_FALSE; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
168 |
CK_ATTRIBUTE ckNetscapeAttributesTemplate[4]; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
169 |
ckNetscapeAttributesTemplate[0].type = CKA_CLASS; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
170 |
ckNetscapeAttributesTemplate[1].type = CKA_KEY_TYPE; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
171 |
ckNetscapeAttributesTemplate[2].type = CKA_SENSITIVE; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
172 |
ckNetscapeAttributesTemplate[3].type = CKA_NETSCAPE_DB; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
173 |
ckNetscapeAttributesTemplate[0].pValue = &class; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
174 |
ckNetscapeAttributesTemplate[1].pValue = &keyType; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
175 |
ckNetscapeAttributesTemplate[2].pValue = &sensitive; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
176 |
ckNetscapeAttributesTemplate[3].pValue = 0; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
177 |
ckNetscapeAttributesTemplate[0].ulValueLen = sizeof(class); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
178 |
ckNetscapeAttributesTemplate[1].ulValueLen = sizeof(keyType); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
179 |
ckNetscapeAttributesTemplate[2].ulValueLen = sizeof(sensitive); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
180 |
ckNetscapeAttributesTemplate[3].ulValueLen = 0; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
181 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
182 |
if (ckpFunctions == NULL) { goto cleanup; } |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
183 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
184 |
// If key is private and of DSA or EC type, NSS may require CKA_NETSCAPE_DB |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
185 |
// attribute to unwrap it. |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
186 |
rv = (*ckpFunctions->C_GetAttributeValue)(ckSessionHandle, ckObjectHandle, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
187 |
ckNetscapeAttributesTemplate, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
188 |
sizeof(ckNetscapeAttributesTemplate)/sizeof(CK_ATTRIBUTE)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
189 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
190 |
if (rv == CKR_OK && class == CKO_PRIVATE_KEY && |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
191 |
(keyType == CKK_EC || keyType == CKK_DSA) && |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
192 |
sensitive == CK_TRUE && |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
193 |
ckNetscapeAttributesTemplate[3].ulValueLen == CK_UNAVAILABLE_INFORMATION) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
194 |
// We cannot set the attribute through C_SetAttributeValue here |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
195 |
// because it might be read-only. However, we can add it to |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
196 |
// the extracted buffer. |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
197 |
netscapeAttributeValueNeeded = CK_TRUE; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
198 |
TRACE0("DEBUG: override CKA_NETSCAPE_DB attr value to TRUE\n"); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
199 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
200 |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
201 |
ckpAttributes = (CK_ATTRIBUTE_PTR) calloc( |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
202 |
CK_ATTRIBUTES_TEMPLATE_LENGTH, sizeof(CK_ATTRIBUTE)); |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
203 |
if (ckpAttributes == NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
204 |
throwOutOfMemoryError(env, 0); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
205 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
206 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
207 |
memcpy(ckpAttributes, ckpAttributesTemplate, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
208 |
CK_ATTRIBUTES_TEMPLATE_LENGTH * sizeof(CK_ATTRIBUTE)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
209 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
210 |
// Get sizes for value buffers |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
211 |
// NOTE: may return an error code but length values are filled anyways |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
212 |
(*ckpFunctions->C_GetAttributeValue)(ckSessionHandle, ckObjectHandle, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
213 |
ckpAttributes, CK_ATTRIBUTES_TEMPLATE_LENGTH); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
214 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
215 |
for (i = 0; i < CK_ATTRIBUTES_TEMPLATE_LENGTH; i++) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
216 |
if ((ckpAttributes+i)->ulValueLen != CK_UNAVAILABLE_INFORMATION) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
217 |
totalDataSize += (ckpAttributes+i)->ulValueLen; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
218 |
if ((ckpAttributes+i)->type == CKA_SENSITIVE) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
219 |
sensitiveAttributePosition = attributesCount; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
220 |
TRACE0("DEBUG: GetNativeKeyInfo key is sensitive"); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
221 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
222 |
attributesCount++; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
223 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
224 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
225 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
226 |
if (netscapeAttributeValueNeeded) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
227 |
attributesCount++; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
228 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
229 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
230 |
// Allocate a single buffer to hold valid attributes and attribute's values |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
231 |
// Buffer structure: [ attributes-size, [ ... attributes ... ], |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
232 |
// values-size, [ ... values ... ], wrapped-key-size, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
233 |
// [ ... wrapped-key ... ] ] |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
234 |
// * sizes are expressed in bytes and data type is unsigned long |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
235 |
totalCkAttributesSize = attributesCount * sizeof(CK_ATTRIBUTE); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
236 |
TRACE1("DEBUG: GetNativeKeyInfo attributesCount = %lu\n", attributesCount); |
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
237 |
TRACE1("DEBUG: GetNativeKeyInfo sizeof CK_ATTRIBUTE = %zu\n", sizeof(CK_ATTRIBUTE)); |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
238 |
TRACE1("DEBUG: GetNativeKeyInfo totalCkAttributesSize = %lu\n", totalCkAttributesSize); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
239 |
TRACE1("DEBUG: GetNativeKeyInfo totalDataSize = %lu\n", totalDataSize); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
240 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
241 |
totalNativeKeyInfoArraySize = |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
242 |
totalCkAttributesSize + sizeof(unsigned long) * 3 + totalDataSize; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
243 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
244 |
TRACE1("DEBUG: GetNativeKeyInfo totalNativeKeyInfoArraySize = %lu\n", totalNativeKeyInfoArraySize); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
245 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
246 |
nativeKeyInfoArray = (*env)->NewByteArray(env, totalNativeKeyInfoArraySize); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
247 |
if (nativeKeyInfoArray == NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
248 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
249 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
250 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
251 |
nativeKeyInfoArrayRaw = (*env)->GetByteArrayElements(env, nativeKeyInfoArray, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
252 |
NULL); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
253 |
if (nativeKeyInfoArrayRaw == NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
254 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
255 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
256 |
|
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
257 |
wrappedKeySizePtr = nativeKeyInfoArrayRaw + |
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
258 |
sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize; |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
259 |
memcpy(nativeKeyInfoArrayRaw, &totalCkAttributesSize, sizeof(unsigned long)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
260 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
261 |
memcpy(nativeKeyInfoArrayRaw + sizeof(unsigned long) + totalCkAttributesSize, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
262 |
&totalDataSize, sizeof(unsigned long)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
263 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
264 |
memset(wrappedKeySizePtr, 0, sizeof(unsigned long)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
265 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
266 |
nativeKeyInfoArrayRawCkAttributes = nativeKeyInfoArrayRaw + |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
267 |
sizeof(unsigned long); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
268 |
nativeKeyInfoArrayRawCkAttributesPtr = nativeKeyInfoArrayRawCkAttributes; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
269 |
nativeKeyInfoArrayRawDataPtr = nativeKeyInfoArrayRaw + |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
270 |
totalCkAttributesSize + sizeof(unsigned long) * 2; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
271 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
272 |
for (i = 0; i < CK_ATTRIBUTES_TEMPLATE_LENGTH; i++) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
273 |
if ((ckpAttributes+i)->ulValueLen != CK_UNAVAILABLE_INFORMATION) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
274 |
(*(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributesPtr).type = |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
275 |
(ckpAttributes+i)->type; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
276 |
(*(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributesPtr).ulValueLen = |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
277 |
(ckpAttributes+i)->ulValueLen; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
278 |
if ((ckpAttributes+i)->ulValueLen != 0) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
279 |
(*(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributesPtr).pValue = |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
280 |
nativeKeyInfoArrayRawDataPtr; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
281 |
} else { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
282 |
(*(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributesPtr).pValue = 0; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
283 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
284 |
nativeKeyInfoArrayRawDataPtr += |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
285 |
(*(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributesPtr).ulValueLen; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
286 |
nativeKeyInfoArrayRawCkAttributesPtr += sizeof(CK_ATTRIBUTE); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
287 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
288 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
289 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
290 |
TRACE0("DEBUG: GetNativeKeyInfo finished prepping nativeKeyInfoArray\n"); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
291 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
292 |
// Get attribute's values |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
293 |
rv = (*ckpFunctions->C_GetAttributeValue)(ckSessionHandle, ckObjectHandle, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
294 |
(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributes, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
295 |
attributesCount); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
296 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
297 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
298 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
299 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
300 |
TRACE0("DEBUG: GetNativeKeyInfo 1st C_GetAttributeValue call passed\n"); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
301 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
302 |
if (netscapeAttributeValueNeeded) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
303 |
(*(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributesPtr).type = CKA_NETSCAPE_DB; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
304 |
// Value is not needed, public key is not used |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
305 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
306 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
307 |
if ((sensitiveAttributePosition != (unsigned int)-1) && |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
308 |
*(CK_BBOOL*)(((CK_ATTRIBUTE_PTR)(((CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributes) |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
309 |
+sensitiveAttributePosition))->pValue) == CK_TRUE) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
310 |
// Key is sensitive. Need to extract it wrapped. |
54578
895a6a380484
8220513: Wrapper Key may get deleted when closing sessions in SunPKCS11 crypto provider
mbalao
parents:
53856
diff
changeset
|
311 |
if (jWrappingKeyHandle != 0) { |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
312 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
313 |
ckpMechanism = jMechanismToCKMechanismPtr(env, jWrappingMech); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
314 |
rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, ckpMechanism, |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
315 |
jLongToCKULong(jWrappingKeyHandle), ckObjectHandle, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
316 |
NULL_PTR, &ckWrappedKeyLength); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
317 |
if (ckWrappedKeyLength != 0) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
318 |
// Allocate space for getting the wrapped key |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
319 |
nativeKeyInfoWrappedKeyArray = (*env)->NewByteArray(env, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
320 |
totalNativeKeyInfoArraySize + ckWrappedKeyLength); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
321 |
if (nativeKeyInfoWrappedKeyArray == NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
322 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
323 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
324 |
nativeKeyInfoWrappedKeyArrayRaw = |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
325 |
(*env)->GetByteArrayElements(env, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
326 |
nativeKeyInfoWrappedKeyArray, NULL); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
327 |
if (nativeKeyInfoWrappedKeyArrayRaw == NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
328 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
329 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
330 |
memcpy(nativeKeyInfoWrappedKeyArrayRaw, nativeKeyInfoArrayRaw, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
331 |
totalNativeKeyInfoArraySize); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
332 |
wrappedKeySizeWrappedKeyArrayPtr = |
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
333 |
nativeKeyInfoWrappedKeyArrayRaw + |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
334 |
sizeof(unsigned long)*2 + totalCkAttributesSize + |
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
335 |
totalDataSize; |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
336 |
memcpy(wrappedKeySizeWrappedKeyArrayPtr, &ckWrappedKeyLength, sizeof(unsigned long)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
337 |
TRACE1("DEBUG: GetNativeKeyInfo 1st C_WrapKey wrappedKeyLength = %lu\n", ckWrappedKeyLength); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
338 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
339 |
wrappedKeyBufferPtr = |
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
340 |
(CK_BYTE_PTR) (wrappedKeySizeWrappedKeyArrayPtr + |
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
341 |
sizeof(unsigned long)); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
342 |
rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, ckpMechanism, |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
343 |
jLongToCKULong(jWrappingKeyHandle),ckObjectHandle, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
344 |
wrappedKeyBufferPtr, &ckWrappedKeyLength); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
345 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
346 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
347 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
348 |
memcpy(wrappedKeySizeWrappedKeyArrayPtr, &ckWrappedKeyLength, sizeof(unsigned long)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
349 |
TRACE1("DEBUG: GetNativeKeyInfo 2nd C_WrapKey wrappedKeyLength = %lu\n", ckWrappedKeyLength); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
350 |
} else { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
351 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
352 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
353 |
} else { |
54578
895a6a380484
8220513: Wrapper Key may get deleted when closing sessions in SunPKCS11 crypto provider
mbalao
parents:
53856
diff
changeset
|
354 |
ckAssertReturnValueOK(env, CKR_KEY_HANDLE_INVALID); |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
355 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
356 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
357 |
returnValue = nativeKeyInfoWrappedKeyArray; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
358 |
} else { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
359 |
returnValue = nativeKeyInfoArray; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
360 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
361 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
362 |
cleanup: |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
363 |
if (ckpAttributes != NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
364 |
free(ckpAttributes); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
365 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
366 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
367 |
if (nativeKeyInfoArrayRaw != NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
368 |
(*env)->ReleaseByteArrayElements(env, nativeKeyInfoArray, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
369 |
nativeKeyInfoArrayRaw, 0); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
370 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
371 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
372 |
if (nativeKeyInfoWrappedKeyArrayRaw != NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
373 |
(*env)->ReleaseByteArrayElements(env, nativeKeyInfoWrappedKeyArray, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
374 |
nativeKeyInfoWrappedKeyArrayRaw, 0); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
375 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
376 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
377 |
if (nativeKeyInfoArray != NULL && returnValue != nativeKeyInfoArray) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
378 |
(*env)->DeleteLocalRef(env, nativeKeyInfoArray); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
379 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
380 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
381 |
if (nativeKeyInfoWrappedKeyArray != NULL |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
382 |
&& returnValue != nativeKeyInfoWrappedKeyArray) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
383 |
(*env)->DeleteLocalRef(env, nativeKeyInfoWrappedKeyArray); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
384 |
} |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
385 |
freeCKMechanismPtr(ckpMechanism); |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
386 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
387 |
return returnValue; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
388 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
389 |
#endif |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
390 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
391 |
#ifdef P11_ENABLE_CREATENATIVEKEY |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
392 |
/* |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
393 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
394 |
* Method: createNativeKey |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
395 |
* Signature: (J[BJLsun/security/pkcs11/wrapper/CK_MECHANISM;)J |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
396 |
* Parametermapping: *PKCS11* |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
397 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
398 |
* @param jbyteArray jNativeKeyInfo - |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
399 |
* @param jlong jWrappingKeyHandle CK_OBJECT_HANDLE hObject |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
400 |
* @param jobject jWrappingMech CK_MECHANISM_PTR pMechanism |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
401 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE hObject |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
402 |
*/ |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
403 |
JNIEXPORT jlong JNICALL |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
404 |
Java_sun_security_pkcs11_wrapper_PKCS11_createNativeKey |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
405 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jNativeKeyInfo, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
406 |
jlong jWrappingKeyHandle, jobject jWrappingMech) |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
407 |
{ |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
408 |
CK_OBJECT_HANDLE ckObjectHandle; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
409 |
CK_RV rv; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
410 |
CK_SESSION_HANDLE ckSessionHandle = jLongToCKULong(jSessionHandle); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
411 |
jbyte* nativeKeyInfoArrayRaw = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
412 |
jlong jObjectHandle = 0L; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
413 |
unsigned long totalCkAttributesSize = 0UL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
414 |
unsigned long nativeKeyInfoCkAttributesCount = 0UL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
415 |
jbyte* nativeKeyInfoArrayRawCkAttributes = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
416 |
jbyte* nativeKeyInfoArrayRawCkAttributesPtr = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
417 |
jbyte* nativeKeyInfoArrayRawDataPtr = NULL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
418 |
unsigned long totalDataSize = 0UL; |
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
419 |
jbyte* wrappedKeySizePtr = NULL; |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
420 |
unsigned int i = 0U; |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
421 |
CK_MECHANISM_PTR ckpMechanism = NULL; |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
422 |
char iv[16] = {0x0}; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
423 |
CK_ULONG ckWrappedKeyLength = 0UL; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
424 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
425 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
426 |
if (ckpFunctions == NULL) { goto cleanup; } |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
427 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
428 |
nativeKeyInfoArrayRaw = |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
429 |
(*env)->GetByteArrayElements(env, jNativeKeyInfo, NULL); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
430 |
if (nativeKeyInfoArrayRaw == NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
431 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
432 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
433 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
434 |
memcpy(&totalCkAttributesSize, nativeKeyInfoArrayRaw, sizeof(unsigned long)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
435 |
TRACE1("DEBUG: createNativeKey totalCkAttributesSize = %lu\n", totalCkAttributesSize); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
436 |
nativeKeyInfoCkAttributesCount = totalCkAttributesSize/sizeof(CK_ATTRIBUTE); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
437 |
TRACE1("DEBUG: createNativeKey nativeKeyInfoCkAttributesCount = %lu\n", nativeKeyInfoCkAttributesCount); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
438 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
439 |
nativeKeyInfoArrayRawCkAttributes = nativeKeyInfoArrayRaw + |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
440 |
sizeof(unsigned long); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
441 |
nativeKeyInfoArrayRawCkAttributesPtr = nativeKeyInfoArrayRawCkAttributes; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
442 |
nativeKeyInfoArrayRawDataPtr = nativeKeyInfoArrayRaw + |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
443 |
totalCkAttributesSize + sizeof(unsigned long) * 2; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
444 |
memcpy(&totalDataSize, (nativeKeyInfoArrayRaw + totalCkAttributesSize + sizeof(unsigned long)), |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
445 |
sizeof(unsigned long)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
446 |
TRACE1("DEBUG: createNativeKey totalDataSize = %lu\n", totalDataSize); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
447 |
|
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
448 |
wrappedKeySizePtr = nativeKeyInfoArrayRaw + |
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
449 |
sizeof(unsigned long)*2 + totalCkAttributesSize + totalDataSize; |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
450 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
451 |
memcpy(&ckWrappedKeyLength, wrappedKeySizePtr, sizeof(unsigned long)); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
452 |
TRACE1("DEBUG: createNativeKey wrappedKeyLength = %lu\n", ckWrappedKeyLength); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
453 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
454 |
for (i = 0; i < nativeKeyInfoCkAttributesCount; i++) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
455 |
if ((*(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributesPtr).ulValueLen |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
456 |
> 0) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
457 |
(*(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributesPtr).pValue = |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
458 |
nativeKeyInfoArrayRawDataPtr; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
459 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
460 |
nativeKeyInfoArrayRawDataPtr += |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
461 |
(*(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributesPtr).ulValueLen; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
462 |
nativeKeyInfoArrayRawCkAttributesPtr += sizeof(CK_ATTRIBUTE); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
463 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
464 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
465 |
if (ckWrappedKeyLength == 0) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
466 |
// Not a wrapped key |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
467 |
rv = (*ckpFunctions->C_CreateObject)(ckSessionHandle, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
468 |
(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributes, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
469 |
jLongToCKULong(nativeKeyInfoCkAttributesCount), &ckObjectHandle); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
470 |
} else { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
471 |
// Wrapped key |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
472 |
ckpMechanism = jMechanismToCKMechanismPtr(env, jWrappingMech); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
473 |
rv = (*ckpFunctions->C_UnwrapKey)(ckSessionHandle, ckpMechanism, |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
474 |
jLongToCKULong(jWrappingKeyHandle), |
53856
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
475 |
(CK_BYTE_PTR)(wrappedKeySizePtr + sizeof(unsigned long)), |
15ae25f7eefd
8216597: SIGBUS in Java_sun_security_pkcs11_wrapper_PKCS11_getNativeKeyInfo after JDK-6913047
valeriep
parents:
53257
diff
changeset
|
476 |
ckWrappedKeyLength, |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
477 |
(CK_ATTRIBUTE_PTR)nativeKeyInfoArrayRawCkAttributes, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
478 |
jLongToCKULong(nativeKeyInfoCkAttributesCount), |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
479 |
&ckObjectHandle); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
480 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
481 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
482 |
goto cleanup; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
483 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
484 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
485 |
jObjectHandle = ckULongToJLong(ckObjectHandle); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
486 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
487 |
cleanup: |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
488 |
|
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
489 |
if (nativeKeyInfoArrayRaw != NULL) { |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
490 |
(*env)->ReleaseByteArrayElements(env, jNativeKeyInfo, |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
491 |
nativeKeyInfoArrayRaw, JNI_ABORT); |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
492 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
493 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
494 |
freeCKMechanismPtr(ckpMechanism); |
53257
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
495 |
return jObjectHandle; |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
496 |
} |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
497 |
#endif |
5170dc2bcf64
6913047: Long term memory leak when using PKCS11 and JCE exceeds 32 bit process address space
mbalao
parents:
51800
diff
changeset
|
498 |
|
2 | 499 |
#ifdef P11_ENABLE_C_GENERATEKEY |
500 |
/* |
|
501 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
502 |
* Method: C_GenerateKey |
|
503 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J |
|
504 |
* Parametermapping: *PKCS11* |
|
505 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
506 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
507 |
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate |
|
508 |
* CK_ULONG ulCount |
|
509 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE_PTR phKey |
|
510 |
*/ |
|
511 |
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKey |
|
512 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jobjectArray jTemplate) |
|
513 |
{ |
|
514 |
CK_SESSION_HANDLE ckSessionHandle; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
515 |
CK_MECHANISM_PTR ckpMechanism = NULL; |
2 | 516 |
CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
517 |
CK_ULONG ckAttributesLength = 0; |
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
518 |
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
|
519 |
jlong jKeyHandle = 0L; |
2 | 520 |
CK_RV rv; |
521 |
||
522 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
523 |
if (ckpFunctions == NULL) { return 0L; } |
|
524 |
||
525 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
526 |
ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism); |
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
|
527 |
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
|
528 |
|
2 | 529 |
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
|
530 |
if ((*env)->ExceptionCheck(env)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
531 |
goto cleanup; |
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
|
532 |
} |
2 | 533 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
534 |
rv = (*ckpFunctions->C_GenerateKey)(ckSessionHandle, ckpMechanism, ckpAttributes, ckAttributesLength, &ckKeyHandle); |
2 | 535 |
|
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
|
536 |
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
|
537 |
jKeyHandle = ckULongToJLong(ckKeyHandle); |
2 | 538 |
|
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
|
539 |
/* cheack, if we must give a initialization vector back to Java */ |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
540 |
switch (ckpMechanism->mechanism) { |
2 | 541 |
case CKM_PBE_MD2_DES_CBC: |
542 |
case CKM_PBE_MD5_DES_CBC: |
|
543 |
case CKM_PBE_MD5_CAST_CBC: |
|
544 |
case CKM_PBE_MD5_CAST3_CBC: |
|
545 |
case CKM_PBE_MD5_CAST128_CBC: |
|
546 |
/* case CKM_PBE_MD5_CAST5_CBC: the same as CKM_PBE_MD5_CAST128_CBC */ |
|
547 |
case CKM_PBE_SHA1_CAST128_CBC: |
|
548 |
/* case CKM_PBE_SHA1_CAST5_CBC: the same as CKM_PBE_SHA1_CAST128_CBC */ |
|
549 |
/* we must copy back the initialization vector to the jMechanism object */ |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
550 |
copyBackPBEInitializationVector(env, ckpMechanism, jMechanism); |
2 | 551 |
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
|
552 |
} |
2 | 553 |
} |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
554 |
cleanup: |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
555 |
freeCKMechanismPtr(ckpMechanism); |
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
|
556 |
freeCKAttributeArray(ckpAttributes, ckAttributesLength); |
2 | 557 |
|
558 |
return jKeyHandle ; |
|
559 |
} |
|
560 |
#endif |
|
561 |
||
562 |
#ifdef P11_ENABLE_C_GENERATEKEYPAIR |
|
563 |
/* |
|
564 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
565 |
* Method: C_GenerateKeyPair |
|
566 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)[J |
|
567 |
* Parametermapping: *PKCS11* |
|
568 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
569 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
570 |
* @param jobjectArray jPublicKeyTemplate CK_ATTRIBUTE_PTR pPublicKeyTemplate |
|
571 |
* CK_ULONG ulPublicKeyAttributeCount |
|
572 |
* @param jobjectArray jPrivateKeyTemplate CK_ATTRIBUTE_PTR pPrivateKeyTemplate |
|
573 |
* CK_ULONG ulPrivateKeyAttributeCount |
|
574 |
* @return jlongArray jKeyHandles CK_OBJECT_HANDLE_PTR phPublicKey |
|
575 |
* CK_OBJECT_HANDLE_PTR phPublicKey |
|
576 |
*/ |
|
577 |
JNIEXPORT jlongArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1GenerateKeyPair |
|
578 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, |
|
579 |
jobjectArray jPublicKeyTemplate, jobjectArray jPrivateKeyTemplate) |
|
580 |
{ |
|
581 |
CK_SESSION_HANDLE ckSessionHandle; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
582 |
CK_MECHANISM_PTR ckpMechanism = NULL; |
2 | 583 |
CK_ATTRIBUTE_PTR ckpPublicKeyAttributes = NULL_PTR; |
584 |
CK_ATTRIBUTE_PTR ckpPrivateKeyAttributes = NULL_PTR; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
585 |
CK_ULONG ckPublicKeyAttributesLength = 0; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
586 |
CK_ULONG ckPrivateKeyAttributesLength = 0; |
2 | 587 |
CK_OBJECT_HANDLE_PTR ckpPublicKeyHandle; /* pointer to Public Key */ |
588 |
CK_OBJECT_HANDLE_PTR ckpPrivateKeyHandle; /* pointer to Private Key */ |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
589 |
CK_OBJECT_HANDLE_PTR ckpKeyHandles = NULL; /* 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
|
590 |
jlongArray jKeyHandles = NULL; |
2 | 591 |
CK_RV rv; |
39142
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
592 |
int attempts; |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
593 |
const int MAX_ATTEMPTS = 3; |
2 | 594 |
|
595 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
596 |
if (ckpFunctions == NULL) { return NULL; } |
|
597 |
||
598 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
599 |
ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism); |
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
|
600 |
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
|
601 |
|
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
602 |
ckpKeyHandles = (CK_OBJECT_HANDLE_PTR) calloc(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
|
603 |
if (ckpKeyHandles == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
604 |
throwOutOfMemoryError(env, 0); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
605 |
goto cleanup; |
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
|
606 |
} |
2 | 607 |
ckpPublicKeyHandle = ckpKeyHandles; /* first element of array is Public Key */ |
608 |
ckpPrivateKeyHandle = (ckpKeyHandles + 1); /* second element of array is Private Key */ |
|
609 |
||
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
|
610 |
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
|
611 |
if ((*env)->ExceptionCheck(env)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
612 |
goto cleanup; |
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
|
613 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
614 |
|
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
615 |
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
|
616 |
if ((*env)->ExceptionCheck(env)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
617 |
goto cleanup; |
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
|
618 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
619 |
|
39142
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
620 |
/* |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
621 |
* Workaround for NSS bug 1012786: |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
622 |
* |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
623 |
* Key generation may fail with CKR_FUNCTION_FAILED error |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
624 |
* if there is insufficient entropy to generate a random key. |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
625 |
* |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
626 |
* PKCS11 spec says the following about CKR_FUNCTION_FAILED error |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
627 |
* (see section 11.1.1): |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
628 |
* |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
629 |
* ... In any event, although the function call failed, the situation |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
630 |
* is not necessarily totally hopeless, as it is likely to be |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
631 |
* when CKR_GENERAL_ERROR is returned. Depending on what the root cause of |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
632 |
* the error actually was, it is possible that an attempt |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
633 |
* to make the exact same function call again would succeed. |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
634 |
* |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
635 |
* Call C_GenerateKeyPair() several times if CKR_FUNCTION_FAILED occurs. |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
636 |
*/ |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
637 |
for (attempts = 0; attempts < MAX_ATTEMPTS; attempts++) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
638 |
rv = (*ckpFunctions->C_GenerateKeyPair)(ckSessionHandle, ckpMechanism, |
39142
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
639 |
ckpPublicKeyAttributes, ckPublicKeyAttributesLength, |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
640 |
ckpPrivateKeyAttributes, ckPrivateKeyAttributesLength, |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
641 |
ckpPublicKeyHandle, ckpPrivateKeyHandle); |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
642 |
if (rv == CKR_FUNCTION_FAILED) { |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
643 |
printDebug("C_1GenerateKeyPair(): C_GenerateKeyPair() failed \ |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
644 |
with CKR_FUNCTION_FAILED error, try again\n"); |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
645 |
} else { |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
646 |
break; |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
647 |
} |
bf48a9f13cf2
8074580: sun/security/pkcs11/rsa/TestKeyPairGenerator.java fails due to PKCS11Exception: CKR_FUNCTION_FAILED
asmotrak
parents:
25859
diff
changeset
|
648 |
} |
2 | 649 |
|
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
|
650 |
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
|
651 |
jKeyHandles = ckULongArrayToJLongArray(env, ckpKeyHandles, 2); |
2 | 652 |
} |
653 |
||
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
654 |
cleanup: |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
655 |
freeCKMechanismPtr(ckpMechanism); |
2 | 656 |
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
|
657 |
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
|
658 |
freeCKAttributeArray(ckpPrivateKeyAttributes, ckPrivateKeyAttributesLength); |
2 | 659 |
return jKeyHandles ; |
660 |
} |
|
661 |
#endif |
|
662 |
||
663 |
#ifdef P11_ENABLE_C_WRAPKEY |
|
664 |
/* |
|
665 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
666 |
* Method: C_WrapKey |
|
667 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;JJ)[B |
|
668 |
* Parametermapping: *PKCS11* |
|
669 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
670 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
671 |
* @param jlong jWrappingKeyHandle CK_OBJECT_HANDLE hWrappingKey |
|
672 |
* @param jlong jKeyHandle CK_OBJECT_HANDLE hKey |
|
673 |
* @return jbyteArray jWrappedKey CK_BYTE_PTR pWrappedKey |
|
674 |
* CK_ULONG_PTR pulWrappedKeyLen |
|
675 |
*/ |
|
676 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1WrapKey |
|
677 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jWrappingKeyHandle, jlong jKeyHandle) |
|
678 |
{ |
|
679 |
CK_SESSION_HANDLE ckSessionHandle; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
680 |
CK_MECHANISM_PTR ckpMechanism = NULL; |
2 | 681 |
CK_OBJECT_HANDLE ckWrappingKeyHandle; |
682 |
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
|
683 |
jbyteArray jWrappedKey = NULL; |
2 | 684 |
CK_RV rv; |
685 |
CK_BYTE BUF[MAX_STACK_BUFFER_LEN]; |
|
686 |
CK_BYTE_PTR ckpWrappedKey = BUF; |
|
687 |
CK_ULONG ckWrappedKeyLength = MAX_STACK_BUFFER_LEN; |
|
688 |
||
689 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
690 |
if (ckpFunctions == NULL) { return NULL; } |
|
691 |
||
692 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
693 |
ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism); |
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 ((*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
|
695 |
|
2 | 696 |
ckWrappingKeyHandle = jLongToCKULong(jWrappingKeyHandle); |
697 |
ckKeyHandle = jLongToCKULong(jKeyHandle); |
|
698 |
||
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
699 |
rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, ckpMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength); |
2 | 700 |
if (rv == CKR_BUFFER_TOO_SMALL) { |
57737
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
701 |
ckpWrappedKey = (CK_BYTE_PTR) |
6bbb4af131e3
8228835: Memory leak in PKCS11 provider when using AES GCM
valeriep
parents:
55332
diff
changeset
|
702 |
calloc(ckWrappedKeyLength, sizeof(CK_BYTE)); |
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
|
703 |
if (ckpWrappedKey == NULL) { |
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
704 |
throwOutOfMemoryError(env, 0); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
705 |
goto cleanup; |
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
|
706 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
707 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
708 |
rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, ckpMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength); |
2 | 709 |
} |
710 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
|
711 |
jWrappedKey = ckByteArrayToJByteArray(env, ckpWrappedKey, ckWrappedKeyLength); |
|
712 |
} |
|
713 |
||
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
714 |
cleanup: |
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
|
715 |
if (ckpWrappedKey != BUF) { free(ckpWrappedKey); } |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
716 |
freeCKMechanismPtr(ckpMechanism); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
717 |
|
2 | 718 |
return jWrappedKey ; |
719 |
} |
|
720 |
#endif |
|
721 |
||
722 |
#ifdef P11_ENABLE_C_UNWRAPKEY |
|
723 |
/* |
|
724 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
725 |
* Method: C_UnwrapKey |
|
726 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J[B[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J |
|
727 |
* Parametermapping: *PKCS11* |
|
728 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
729 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
730 |
* @param jlong jUnwrappingKeyHandle CK_OBJECT_HANDLE hUnwrappingKey |
|
731 |
* @param jbyteArray jWrappedKey CK_BYTE_PTR pWrappedKey |
|
732 |
* CK_ULONG_PTR pulWrappedKeyLen |
|
733 |
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate |
|
734 |
* CK_ULONG ulCount |
|
735 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE_PTR phKey |
|
736 |
*/ |
|
737 |
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1UnwrapKey |
|
738 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jUnwrappingKeyHandle, |
|
739 |
jbyteArray jWrappedKey, jobjectArray jTemplate) |
|
740 |
{ |
|
741 |
CK_SESSION_HANDLE ckSessionHandle; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
742 |
CK_MECHANISM_PTR ckpMechanism = NULL; |
2 | 743 |
CK_OBJECT_HANDLE ckUnwrappingKeyHandle; |
744 |
CK_BYTE_PTR ckpWrappedKey = NULL_PTR; |
|
745 |
CK_ULONG ckWrappedKeyLength; |
|
746 |
CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
747 |
CK_ULONG ckAttributesLength = 0; |
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
748 |
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
|
749 |
jlong jKeyHandle = 0L; |
2 | 750 |
CK_RV rv; |
751 |
||
752 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
753 |
if (ckpFunctions == NULL) { return 0L; } |
|
754 |
||
755 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
756 |
ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism); |
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
|
757 |
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
|
758 |
|
2 | 759 |
ckUnwrappingKeyHandle = jLongToCKULong(jUnwrappingKeyHandle); |
760 |
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
|
761 |
if ((*env)->ExceptionCheck(env)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
762 |
goto cleanup; |
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
|
763 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
764 |
|
2 | 765 |
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
|
766 |
if ((*env)->ExceptionCheck(env)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
767 |
goto cleanup; |
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
|
768 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
769 |
|
2 | 770 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
771 |
rv = (*ckpFunctions->C_UnwrapKey)(ckSessionHandle, ckpMechanism, ckUnwrappingKeyHandle, |
2 | 772 |
ckpWrappedKey, ckWrappedKeyLength, |
773 |
ckpAttributes, ckAttributesLength, &ckKeyHandle); |
|
774 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
775 |
if (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
|
776 |
jKeyHandle = ckLongToJLong(ckKeyHandle); |
2 | 777 |
|
778 |
#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
|
779 |
/* cheack, if we must give a initialization vector back to Java */ |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
780 |
if (ckpMechanism->mechanism == CKM_KEY_WRAP_SET_OAEP) { |
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
|
781 |
/* we must copy back the unwrapped key info to the jMechanism object */ |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
782 |
copyBackSetUnwrappedKey(env, ckpMechanism, jMechanism); |
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
|
783 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
784 |
#endif |
2 | 785 |
} |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
786 |
cleanup: |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
787 |
freeCKMechanismPtr(ckpMechanism); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
788 |
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
|
789 |
free(ckpWrappedKey); |
2 | 790 |
|
791 |
return jKeyHandle ; |
|
792 |
} |
|
793 |
#endif |
|
794 |
||
795 |
#ifdef P11_ENABLE_C_DERIVEKEY |
|
796 |
||
797 |
/* |
|
798 |
* Copy back the PRF output to Java. |
|
799 |
*/ |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
800 |
void copyBackTLSPrfParams(JNIEnv *env, CK_MECHANISM_PTR ckpMechanism, jobject jMechanism) |
2 | 801 |
{ |
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
|
802 |
jclass jMechanismClass, jTLSPrfParamsClass; |
2 | 803 |
CK_TLS_PRF_PARAMS *ckTLSPrfParams; |
804 |
jobject jTLSPrfParams; |
|
805 |
jfieldID fieldID; |
|
806 |
CK_MECHANISM_TYPE ckMechanismType; |
|
807 |
jlong jMechanismType; |
|
808 |
CK_BYTE_PTR output; |
|
809 |
jobject jOutput; |
|
810 |
jint jLength; |
|
811 |
jbyte* jBytes; |
|
812 |
int i; |
|
813 |
||
814 |
/* 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
|
815 |
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
|
816 |
if (jMechanismClass == NULL) { return; } |
2 | 817 |
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
|
818 |
if (fieldID == NULL) { return; } |
2 | 819 |
jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); |
820 |
ckMechanismType = jLongToCKULong(jMechanismType); |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
821 |
if (ckMechanismType != ckpMechanism->mechanism) { |
2 | 822 |
/* we do not have maching types, this should not occur */ |
823 |
return; |
|
824 |
} |
|
825 |
||
826 |
/* get the native CK_TLS_PRF_PARAMS */ |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
827 |
ckTLSPrfParams = (CK_TLS_PRF_PARAMS *) ckpMechanism->pParameter; |
2 | 828 |
if (ckTLSPrfParams != NULL_PTR) { |
829 |
/* get the Java CK_TLS_PRF_PARAMS object (pParameter) */ |
|
830 |
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
|
831 |
if (fieldID == NULL) { return; } |
2 | 832 |
jTLSPrfParams = (*env)->GetObjectField(env, jMechanism, fieldID); |
833 |
||
834 |
/* 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
|
835 |
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
|
836 |
if (jTLSPrfParamsClass == NULL) { return; } |
2 | 837 |
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
|
838 |
if (fieldID == NULL) { return; } |
2 | 839 |
jOutput = (*env)->GetObjectField(env, jTLSPrfParams, fieldID); |
840 |
output = ckTLSPrfParams->pOutput; |
|
841 |
||
842 |
// Note: we assume that the token returned exactly as many bytes as we |
|
843 |
// requested. Anything else would not make sense. |
|
844 |
if (jOutput != NULL) { |
|
845 |
jLength = (*env)->GetArrayLength(env, jOutput); |
|
846 |
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
|
847 |
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
|
848 |
|
2 | 849 |
/* copy the bytes to the Java buffer */ |
850 |
for (i=0; i < jLength; i++) { |
|
851 |
jBytes[i] = ckByteToJByte(output[i]); |
|
852 |
} |
|
853 |
/* copy back the Java buffer to the object */ |
|
854 |
(*env)->ReleaseByteArrayElements(env, jOutput, jBytes, 0); |
|
855 |
} |
|
856 |
} |
|
857 |
} |
|
858 |
||
859 |
/* |
|
860 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
861 |
* Method: C_DeriveKey |
|
862 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J |
|
863 |
* Parametermapping: *PKCS11* |
|
864 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
865 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
866 |
* @param jlong jBaseKeyHandle CK_OBJECT_HANDLE hBaseKey |
|
867 |
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate |
|
868 |
* CK_ULONG ulCount |
|
869 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE_PTR phKey |
|
870 |
*/ |
|
871 |
JNIEXPORT jlong JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1DeriveKey |
|
872 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jBaseKeyHandle, jobjectArray jTemplate) |
|
873 |
{ |
|
874 |
CK_SESSION_HANDLE ckSessionHandle; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
875 |
CK_MECHANISM_PTR ckpMechanism = NULL; |
2 | 876 |
CK_OBJECT_HANDLE ckBaseKeyHandle; |
877 |
CK_ATTRIBUTE_PTR ckpAttributes = NULL_PTR; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
878 |
CK_ULONG ckAttributesLength = 0; |
2 | 879 |
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
|
880 |
jlong jKeyHandle = 0L; |
2 | 881 |
CK_RV rv; |
882 |
CK_OBJECT_HANDLE_PTR phKey = &ckKeyHandle; |
|
883 |
||
884 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
885 |
if (ckpFunctions == NULL) { return 0L; } |
|
886 |
||
887 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
888 |
ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism); |
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
|
889 |
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
|
890 |
|
2 | 891 |
ckBaseKeyHandle = jLongToCKULong(jBaseKeyHandle); |
892 |
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
|
893 |
if ((*env)->ExceptionCheck(env)) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
894 |
goto cleanup; |
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
|
895 |
} |
2 | 896 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
897 |
switch (ckpMechanism->mechanism) { |
2 | 898 |
case CKM_SSL3_KEY_AND_MAC_DERIVE: |
899 |
case CKM_TLS_KEY_AND_MAC_DERIVE: |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
900 |
case CKM_TLS12_KEY_AND_MAC_DERIVE: |
2 | 901 |
case CKM_TLS_PRF: |
902 |
// these mechanism do not return a key handle via phKey |
|
903 |
// set to NULL in case pedantic implementations check for it |
|
904 |
phKey = NULL; |
|
905 |
break; |
|
906 |
default: |
|
907 |
// empty |
|
908 |
break; |
|
909 |
} |
|
910 |
||
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
911 |
rv = (*ckpFunctions->C_DeriveKey)(ckSessionHandle, ckpMechanism, ckBaseKeyHandle, |
2 | 912 |
ckpAttributes, ckAttributesLength, phKey); |
913 |
||
914 |
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
|
915 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
916 |
switch (ckpMechanism->mechanism) { |
2 | 917 |
case CKM_SSL3_MASTER_KEY_DERIVE: |
918 |
case CKM_TLS_MASTER_KEY_DERIVE: |
|
919 |
/* we must copy back the client version */ |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
920 |
ssl3CopyBackClientVersion(env, ckpMechanism, jMechanism); |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
921 |
break; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
922 |
case CKM_TLS12_MASTER_KEY_DERIVE: |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
923 |
tls12CopyBackClientVersion(env, ckpMechanism, jMechanism); |
2 | 924 |
break; |
925 |
case CKM_SSL3_KEY_AND_MAC_DERIVE: |
|
926 |
case CKM_TLS_KEY_AND_MAC_DERIVE: |
|
927 |
/* we must copy back the unwrapped key info to the jMechanism object */ |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
928 |
ssl3CopyBackKeyMatParams(env, ckpMechanism, jMechanism); |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
929 |
break; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
930 |
case CKM_TLS12_KEY_AND_MAC_DERIVE: |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
931 |
/* we must copy back the unwrapped key info to the jMechanism object */ |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
932 |
tls12CopyBackKeyMatParams(env, ckpMechanism, jMechanism); |
2 | 933 |
break; |
934 |
case CKM_TLS_PRF: |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
935 |
copyBackTLSPrfParams(env, ckpMechanism, jMechanism); |
2 | 936 |
break; |
937 |
default: |
|
938 |
// empty |
|
939 |
break; |
|
940 |
} |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
941 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
942 |
jKeyHandle =0L; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
943 |
} |
2 | 944 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
945 |
cleanup: |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
946 |
freeCKMechanismPtr(ckpMechanism); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
947 |
freeCKAttributeArray(ckpAttributes, ckAttributesLength); |
2 | 948 |
|
949 |
return jKeyHandle ; |
|
950 |
} |
|
951 |
||
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
952 |
static void copyBackClientVersion(JNIEnv *env, CK_MECHANISM_PTR ckpMechanism, jobject jMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
953 |
CK_VERSION *ckVersion, const char *class_master_key_derive_params) |
2 | 954 |
{ |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
955 |
jclass jMasterKeyDeriveParamsClass, jMechanismClass, jVersionClass; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
956 |
jobject jMasterKeyDeriveParams; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
957 |
jfieldID fieldID; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
958 |
CK_MECHANISM_TYPE ckMechanismType; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
959 |
jlong jMechanismType; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
960 |
jobject jVersion; |
2 | 961 |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
962 |
/* get mechanism */ |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
963 |
jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
964 |
if (jMechanismClass == NULL) { return; } |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
965 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
966 |
if (fieldID == NULL) { return; } |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
967 |
jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
968 |
ckMechanismType = jLongToCKULong(jMechanismType); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
969 |
if (ckMechanismType != ckpMechanism->mechanism) { |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
970 |
/* we do not have maching types, this should not occur */ |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
971 |
return; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
972 |
} |
2 | 973 |
|
974 |
if (ckVersion != NULL_PTR) { |
|
975 |
/* get the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS (pParameter) */ |
|
976 |
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
|
977 |
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
|
978 |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
979 |
jMasterKeyDeriveParams = (*env)->GetObjectField(env, jMechanism, fieldID); |
2 | 980 |
|
981 |
/* get the Java CK_VERSION */ |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
982 |
jMasterKeyDeriveParamsClass = (*env)->FindClass(env, class_master_key_derive_params); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
983 |
if (jMasterKeyDeriveParamsClass == NULL) { return; } |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
984 |
fieldID = (*env)->GetFieldID(env, jMasterKeyDeriveParamsClass, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
985 |
"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
|
986 |
if (fieldID == NULL) { return; } |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
987 |
jVersion = (*env)->GetObjectField(env, jMasterKeyDeriveParams, fieldID); |
2 | 988 |
|
989 |
/* now copy back the version from the native structure to the Java structure */ |
|
990 |
||
991 |
/* 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
|
992 |
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
|
993 |
if (jVersionClass == NULL) { return; } |
2 | 994 |
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
|
995 |
if (fieldID == NULL) { return; } |
2 | 996 |
(*env)->SetByteField(env, jVersion, fieldID, ckByteToJByte(ckVersion->major)); |
997 |
||
998 |
/* copy back the minor version */ |
|
999 |
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
|
1000 |
if (fieldID == NULL) { return; } |
2 | 1001 |
(*env)->SetByteField(env, jVersion, fieldID, ckByteToJByte(ckVersion->minor)); |
1002 |
} |
|
1003 |
} |
|
1004 |
||
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1005 |
/* |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1006 |
* Copy back the client version information from the native |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1007 |
* structure to the Java object. This is only used for |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1008 |
* CKM_SSL3_MASTER_KEY_DERIVE and CKM_TLS_MASTER_KEY_DERIVE |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1009 |
* mechanisms when used for deriving a key. |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1010 |
* |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1011 |
*/ |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1012 |
void ssl3CopyBackClientVersion(JNIEnv *env, CK_MECHANISM_PTR ckpMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1013 |
jobject jMechanism) |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1014 |
{ |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1015 |
CK_SSL3_MASTER_KEY_DERIVE_PARAMS *ckSSL3MasterKeyDeriveParams; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1016 |
ckSSL3MasterKeyDeriveParams = |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1017 |
(CK_SSL3_MASTER_KEY_DERIVE_PARAMS *)ckpMechanism->pParameter; |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1018 |
if (ckSSL3MasterKeyDeriveParams != NULL_PTR) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1019 |
copyBackClientVersion(env, ckpMechanism, jMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1020 |
ckSSL3MasterKeyDeriveParams->pVersion, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1021 |
CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1022 |
} |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1023 |
} |
2 | 1024 |
|
1025 |
/* |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1026 |
* Copy back the client version information from the native |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1027 |
* structure to the Java object. This is only used for |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1028 |
* CKM_TLS12_MASTER_KEY_DERIVE mechanism when used for deriving a key. |
2 | 1029 |
* |
1030 |
*/ |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1031 |
void tls12CopyBackClientVersion(JNIEnv *env, CK_MECHANISM_PTR ckpMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1032 |
jobject jMechanism) |
2 | 1033 |
{ |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1034 |
CK_TLS12_MASTER_KEY_DERIVE_PARAMS *ckTLS12MasterKeyDeriveParams; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1035 |
ckTLS12MasterKeyDeriveParams = |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1036 |
(CK_TLS12_MASTER_KEY_DERIVE_PARAMS *)ckpMechanism->pParameter; |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1037 |
if (ckTLS12MasterKeyDeriveParams != NULL_PTR) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1038 |
copyBackClientVersion(env, ckpMechanism, jMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1039 |
ckTLS12MasterKeyDeriveParams->pVersion, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1040 |
CLASS_TLS12_MASTER_KEY_DERIVE_PARAMS); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1041 |
} |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1042 |
} |
2 | 1043 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1044 |
static void copyBackKeyMatParams(JNIEnv *env, CK_MECHANISM_PTR ckpMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1045 |
jobject jMechanism, CK_SSL3_RANDOM_DATA *RandomInfo, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1046 |
CK_SSL3_KEY_MAT_OUT_PTR ckSSL3KeyMatOut, const char *class_key_mat_params) |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1047 |
{ |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1048 |
jclass jMechanismClass, jKeyMatParamsClass, jSSL3KeyMatOutClass; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1049 |
jfieldID fieldID; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1050 |
CK_MECHANISM_TYPE ckMechanismType; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1051 |
jlong jMechanismType; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1052 |
CK_BYTE_PTR iv; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1053 |
jobject jKeyMatParam; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1054 |
jobject jSSL3KeyMatOut; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1055 |
jobject jIV; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1056 |
jint jLength; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1057 |
jbyte* jBytes; |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1058 |
int i; |
2 | 1059 |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1060 |
/* get mechanism */ |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1061 |
jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1062 |
if (jMechanismClass == NULL) { return; } |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1063 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1064 |
if (fieldID == NULL) { return; } |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1065 |
jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1066 |
ckMechanismType = jLongToCKULong(jMechanismType); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1067 |
if (ckMechanismType != ckpMechanism->mechanism) { |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1068 |
/* we do not have maching types, this should not occur */ |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1069 |
return; |
2 | 1070 |
} |
1071 |
||
1072 |
if (ckSSL3KeyMatOut != NULL_PTR) { |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1073 |
/* get the Java params object (pParameter) */ |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1074 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1075 |
"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
|
1076 |
if (fieldID == NULL) { return; } |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1077 |
jKeyMatParam = (*env)->GetObjectField(env, jMechanism, fieldID); |
2 | 1078 |
|
1079 |
/* get the Java CK_SSL3_KEY_MAT_OUT */ |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1080 |
jKeyMatParamsClass = (*env)->FindClass(env, class_key_mat_params); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1081 |
if (jKeyMatParamsClass == NULL) { return; } |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1082 |
fieldID = (*env)->GetFieldID(env, jKeyMatParamsClass, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1083 |
"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
|
1084 |
if (fieldID == NULL) { return; } |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1085 |
jSSL3KeyMatOut = (*env)->GetObjectField(env, jKeyMatParam, fieldID); |
2 | 1086 |
|
1087 |
/* now copy back all the key handles and the initialization vectors */ |
|
1088 |
/* 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
|
1089 |
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
|
1090 |
if (jSSL3KeyMatOutClass == NULL) { return; } |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1091 |
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1092 |
"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
|
1093 |
if (fieldID == NULL) { return; } |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1094 |
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1095 |
ckULongToJLong(ckSSL3KeyMatOut->hClientMacSecret)); |
2 | 1096 |
|
1097 |
/* copy back server MAC secret handle */ |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1098 |
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatOutClass, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1099 |
"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
|
1100 |
if (fieldID == NULL) { return; } |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1101 |
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1102 |
ckULongToJLong(ckSSL3KeyMatOut->hServerMacSecret)); |
2 | 1103 |
|
1104 |
/* copy back client secret key handle */ |
|
1105 |
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
|
1106 |
if (fieldID == NULL) { return; } |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1107 |
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1108 |
ckULongToJLong(ckSSL3KeyMatOut->hClientKey)); |
2 | 1109 |
|
1110 |
/* copy back server secret key handle */ |
|
1111 |
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
|
1112 |
if (fieldID == NULL) { return; } |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1113 |
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1114 |
ckULongToJLong(ckSSL3KeyMatOut->hServerKey)); |
2 | 1115 |
|
1116 |
/* copy back the client IV */ |
|
1117 |
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
|
1118 |
if (fieldID == NULL) { return; } |
2 | 1119 |
jIV = (*env)->GetObjectField(env, jSSL3KeyMatOut, fieldID); |
1120 |
iv = ckSSL3KeyMatOut->pIVClient; |
|
1121 |
||
1122 |
if (jIV != NULL) { |
|
1123 |
jLength = (*env)->GetArrayLength(env, jIV); |
|
1124 |
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
|
1125 |
if (jBytes == NULL) { return; } |
2 | 1126 |
/* copy the bytes to the Java buffer */ |
1127 |
for (i=0; i < jLength; i++) { |
|
1128 |
jBytes[i] = ckByteToJByte(iv[i]); |
|
1129 |
} |
|
1130 |
/* copy back the Java buffer to the object */ |
|
1131 |
(*env)->ReleaseByteArrayElements(env, jIV, jBytes, 0); |
|
1132 |
} |
|
1133 |
||
1134 |
/* copy back the server IV */ |
|
1135 |
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
|
1136 |
if (fieldID == NULL) { return; } |
2 | 1137 |
jIV = (*env)->GetObjectField(env, jSSL3KeyMatOut, fieldID); |
1138 |
iv = ckSSL3KeyMatOut->pIVServer; |
|
1139 |
||
1140 |
if (jIV != NULL) { |
|
1141 |
jLength = (*env)->GetArrayLength(env, jIV); |
|
1142 |
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
|
1143 |
if (jBytes == NULL) { return; } |
2 | 1144 |
/* copy the bytes to the Java buffer */ |
1145 |
for (i=0; i < jLength; i++) { |
|
1146 |
jBytes[i] = ckByteToJByte(iv[i]); |
|
1147 |
} |
|
1148 |
/* copy back the Java buffer to the object */ |
|
1149 |
(*env)->ReleaseByteArrayElements(env, jIV, jBytes, 0); |
|
1150 |
} |
|
1151 |
} |
|
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1152 |
} |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1153 |
|
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1154 |
/* |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1155 |
* Copy back the derived keys and initialization vectors from the native |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1156 |
* structure to the Java object. This is only used for |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1157 |
* CKM_SSL3_KEY_AND_MAC_DERIVE and CKM_TLS_KEY_AND_MAC_DERIVE mechanisms |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1158 |
* when used for deriving a key. |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1159 |
* |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1160 |
*/ |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1161 |
void ssl3CopyBackKeyMatParams(JNIEnv *env, CK_MECHANISM_PTR ckpMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1162 |
jobject jMechanism) |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1163 |
{ |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1164 |
CK_SSL3_KEY_MAT_PARAMS *ckSSL3KeyMatParam; |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1165 |
ckSSL3KeyMatParam = (CK_SSL3_KEY_MAT_PARAMS *)ckpMechanism->pParameter; |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1166 |
if (ckSSL3KeyMatParam != NULL_PTR) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1167 |
copyBackKeyMatParams(env, ckpMechanism, jMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1168 |
&(ckSSL3KeyMatParam->RandomInfo), |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1169 |
ckSSL3KeyMatParam->pReturnedKeyMaterial, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1170 |
CLASS_SSL3_KEY_MAT_PARAMS); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1171 |
} |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1172 |
} |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1173 |
|
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1174 |
/* |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1175 |
* Copy back the derived keys and initialization vectors from the native |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1176 |
* structure to the Java object. This is only used for |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1177 |
* CKM_TLS12_KEY_AND_MAC_DERIVE mechanism when used for deriving a key. |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1178 |
* |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1179 |
*/ |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1180 |
void tls12CopyBackKeyMatParams(JNIEnv *env, CK_MECHANISM_PTR ckpMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1181 |
jobject jMechanism) |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1182 |
{ |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1183 |
CK_TLS12_KEY_MAT_PARAMS *ckTLS12KeyMatParam; |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1184 |
ckTLS12KeyMatParam = (CK_TLS12_KEY_MAT_PARAMS *)ckpMechanism->pParameter; |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1185 |
if (ckTLS12KeyMatParam != NULL_PTR) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
54578
diff
changeset
|
1186 |
copyBackKeyMatParams(env, ckpMechanism, jMechanism, |
51800
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1187 |
&(ckTLS12KeyMatParam->RandomInfo), |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1188 |
ckTLS12KeyMatParam->pReturnedKeyMaterial, |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1189 |
CLASS_TLS12_KEY_MAT_PARAMS); |
bccd9966f1ed
8029661: Support TLS v1.2 algorithm in SunPKCS11 provider
mbalao
parents:
47216
diff
changeset
|
1190 |
} |
2 | 1191 |
} |
1192 |
||
1193 |
#endif |