author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 3321 | fed33393bc52 |
child 10798 | 413b731e1818 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2003, 2009, 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 |
||
57 |
#ifdef P11_ENABLE_C_SIGNINIT |
|
58 |
/* |
|
59 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
60 |
* Method: C_SignInit |
|
61 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V |
|
62 |
* Parametermapping: *PKCS11* |
|
63 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
64 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
65 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE hKey |
|
66 |
*/ |
|
67 |
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignInit |
|
68 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jKeyHandle) |
|
69 |
{ |
|
70 |
CK_SESSION_HANDLE ckSessionHandle; |
|
71 |
CK_MECHANISM ckMechanism; |
|
72 |
CK_OBJECT_HANDLE ckKeyHandle; |
|
73 |
CK_RV rv; |
|
74 |
||
75 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
76 |
if (ckpFunctions == NULL) { return; } |
|
77 |
||
78 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
79 |
jMechanismToCKMechanism(env, jMechanism, &ckMechanism); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
80 |
if ((*env)->ExceptionCheck(env)) { return; } |
2 | 81 |
ckKeyHandle = jLongToCKULong(jKeyHandle); |
82 |
||
83 |
rv = (*ckpFunctions->C_SignInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); |
|
84 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
85 |
if (ckMechanism.pParameter != NULL_PTR) { |
2 | 86 |
free(ckMechanism.pParameter); |
87 |
} |
|
88 |
||
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
|
89 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
2 | 90 |
} |
91 |
#endif |
|
92 |
||
93 |
#ifdef P11_ENABLE_C_SIGN |
|
94 |
/* |
|
95 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
96 |
* Method: C_Sign |
|
97 |
* Signature: (J[B)[B |
|
98 |
* Parametermapping: *PKCS11* |
|
99 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
100 |
* @param jbyteArray jData CK_BYTE_PTR pData |
|
101 |
* CK_ULONG ulDataLen |
|
102 |
* @return jbyteArray jSignature CK_BYTE_PTR pSignature |
|
103 |
* CK_ULONG_PTR pulSignatureLen |
|
104 |
*/ |
|
105 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Sign |
|
106 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jData) |
|
107 |
{ |
|
108 |
CK_SESSION_HANDLE ckSessionHandle; |
|
109 |
CK_BYTE_PTR ckpData = NULL_PTR; |
|
110 |
CK_BYTE_PTR ckpSignature; |
|
111 |
CK_ULONG ckDataLength; |
|
112 |
CK_ULONG ckSignatureLength = 0; |
|
3321
fed33393bc52
6823905: crash in sun.security.pkcs11.wrapper.PKCS11.C_Sign during stress-test
valeriep
parents:
2180
diff
changeset
|
113 |
jbyteArray jSignature = NULL; |
2 | 114 |
CK_RV rv; |
115 |
||
116 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
117 |
if (ckpFunctions == NULL) { return NULL; } |
|
118 |
||
119 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
120 |
jByteArrayToCKByteArray(env, jData, &ckpData, &ckDataLength); |
|
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
|
121 |
if ((*env)->ExceptionCheck(env)) { return NULL; } |
2 | 122 |
|
123 |
/* START standard code */ |
|
124 |
||
125 |
/* first determine the length of the signature */ |
|
126 |
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, NULL_PTR, &ckSignatureLength); |
|
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
|
127 |
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
|
128 |
free(ckpData); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
129 |
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
|
130 |
} |
2 | 131 |
|
132 |
ckpSignature = (CK_BYTE_PTR) malloc(ckSignatureLength * 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
|
133 |
if (ckpSignature == 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
|
134 |
free(ckpData); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
135 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
136 |
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
|
137 |
} |
2 | 138 |
|
139 |
/* now get the signature */ |
|
140 |
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength); |
|
141 |
/* END standard code */ |
|
142 |
||
143 |
||
144 |
/* START workaround code for operation abort bug in pkcs#11 of Datakey and iButton */ |
|
145 |
/* |
|
146 |
ckpSignature = (CK_BYTE_PTR) malloc(256 * 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
|
147 |
if (ckpSignature == 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
|
148 |
free(ckpData); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
149 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
150 |
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
|
151 |
} |
2 | 152 |
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength); |
153 |
||
154 |
if (rv == CKR_BUFFER_TOO_SMALL) { |
|
155 |
free(ckpSignature); |
|
156 |
ckpSignature = (CK_BYTE_PTR) malloc(ckSignatureLength * 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
|
157 |
if (ckpSignature == 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
|
158 |
free(ckpData); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
159 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
160 |
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
|
161 |
} |
2 | 162 |
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength); |
163 |
} |
|
164 |
*/ |
|
165 |
/* END workaround code */ |
|
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
|
166 |
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
|
167 |
jSignature = ckByteArrayToJByteArray(env, ckpSignature, ckSignatureLength); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
168 |
} |
2 | 169 |
free(ckpData); |
170 |
free(ckpSignature); |
|
171 |
||
172 |
return jSignature ; |
|
173 |
} |
|
174 |
#endif |
|
175 |
||
176 |
#ifdef P11_ENABLE_C_SIGNUPDATE |
|
177 |
/* |
|
178 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
179 |
* Method: C_SignUpdate |
|
180 |
* Signature: (J[BII)V |
|
181 |
* Parametermapping: *PKCS11* |
|
182 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
183 |
* @param jbyteArray jPart CK_BYTE_PTR pPart |
|
184 |
* CK_ULONG ulPartLen |
|
185 |
*/ |
|
186 |
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignUpdate |
|
187 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen) |
|
188 |
{ |
|
189 |
CK_SESSION_HANDLE ckSessionHandle; |
|
190 |
CK_RV rv; |
|
191 |
CK_BYTE_PTR bufP; |
|
192 |
CK_BYTE BUF[MAX_STACK_BUFFER_LEN]; |
|
193 |
jsize bufLen; |
|
194 |
||
195 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
196 |
if (ckpFunctions == NULL) { return; } |
|
197 |
||
198 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
199 |
||
200 |
if (directIn != 0) { |
|
201 |
rv = (*ckpFunctions->C_SignUpdate)(ckSessionHandle, (CK_BYTE_PTR)directIn, jInLen); |
|
202 |
ckAssertReturnValueOK(env, rv); |
|
203 |
return; |
|
204 |
} |
|
205 |
||
206 |
if (jInLen <= MAX_STACK_BUFFER_LEN) { |
|
207 |
bufLen = MAX_STACK_BUFFER_LEN; |
|
208 |
bufP = BUF; |
|
209 |
} else { |
|
210 |
bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen); |
|
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
|
211 |
bufP = (CK_BYTE_PTR) malloc((size_t)bufLen); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
212 |
if (bufP == 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
|
213 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
214 |
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
|
215 |
} |
2 | 216 |
} |
217 |
||
218 |
while (jInLen > 0) { |
|
219 |
jsize chunkLen = min(bufLen, jInLen); |
|
220 |
(*env)->GetByteArrayRegion(env, jIn, jInOfs, chunkLen, (jbyte *)bufP); |
|
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
|
221 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
222 |
if (bufP != BUF) { free(bufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
223 |
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
|
224 |
} |
2 | 225 |
rv = (*ckpFunctions->C_SignUpdate)(ckSessionHandle, bufP, chunkLen); |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
226 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { |
2 | 227 |
if (bufP != BUF) { |
228 |
free(bufP); |
|
229 |
} |
|
230 |
return; |
|
231 |
} |
|
232 |
jInOfs += chunkLen; |
|
233 |
jInLen -= chunkLen; |
|
234 |
} |
|
235 |
||
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
|
236 |
if (bufP != BUF) { free(bufP); } |
2 | 237 |
} |
238 |
#endif |
|
239 |
||
240 |
#ifdef P11_ENABLE_C_SIGNFINAL |
|
241 |
/* |
|
242 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
243 |
* Method: C_SignFinal |
|
244 |
* Signature: (J)[B |
|
245 |
* Parametermapping: *PKCS11* |
|
246 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
247 |
* @return jbyteArray jSignature CK_BYTE_PTR pSignature |
|
248 |
* CK_ULONG_PTR pulSignatureLen |
|
249 |
*/ |
|
250 |
JNIEXPORT jbyteArray JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignFinal |
|
251 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jint jExpectedLength) |
|
252 |
{ |
|
253 |
CK_SESSION_HANDLE ckSessionHandle; |
|
254 |
jbyteArray jSignature = NULL; |
|
255 |
CK_RV rv; |
|
256 |
CK_BYTE BUF[MAX_STACK_BUFFER_LEN]; |
|
257 |
CK_BYTE_PTR bufP = BUF; |
|
258 |
CK_ULONG ckSignatureLength = MAX_STACK_BUFFER_LEN; |
|
259 |
||
260 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
261 |
if (ckpFunctions == NULL) { return NULL; } |
|
262 |
||
263 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
264 |
||
265 |
if ((jExpectedLength > 0) && (jExpectedLength < ckSignatureLength)) { |
|
266 |
ckSignatureLength = jExpectedLength; |
|
267 |
} |
|
268 |
||
269 |
rv = (*ckpFunctions->C_SignFinal)(ckSessionHandle, bufP, &ckSignatureLength); |
|
270 |
if (rv == CKR_BUFFER_TOO_SMALL) { |
|
271 |
bufP = (CK_BYTE_PTR) malloc(ckSignatureLength); |
|
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
|
272 |
if (bufP == 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
|
273 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
274 |
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
|
275 |
} |
2 | 276 |
rv = (*ckpFunctions->C_SignFinal)(ckSessionHandle, bufP, &ckSignatureLength); |
277 |
} |
|
278 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
|
279 |
jSignature = ckByteArrayToJByteArray(env, bufP, ckSignatureLength); |
|
280 |
} |
|
281 |
||
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
|
282 |
if (bufP != BUF) { free(bufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
283 |
|
2 | 284 |
return jSignature; |
285 |
} |
|
286 |
#endif |
|
287 |
||
288 |
#ifdef P11_ENABLE_C_SIGNRECOVERINIT |
|
289 |
/* |
|
290 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
291 |
* Method: C_SignRecoverInit |
|
292 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V |
|
293 |
* Parametermapping: *PKCS11* |
|
294 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
295 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
296 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE hKey |
|
297 |
*/ |
|
298 |
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecoverInit |
|
299 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jKeyHandle) |
|
300 |
{ |
|
301 |
CK_SESSION_HANDLE ckSessionHandle; |
|
302 |
CK_MECHANISM ckMechanism; |
|
303 |
CK_OBJECT_HANDLE ckKeyHandle; |
|
304 |
CK_RV rv; |
|
305 |
||
306 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
307 |
if (ckpFunctions == NULL) { return; } |
|
308 |
||
309 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
310 |
jMechanismToCKMechanism(env, jMechanism, &ckMechanism); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
311 |
if ((*env)->ExceptionCheck(env)) { return; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
312 |
|
2 | 313 |
ckKeyHandle = jLongToCKULong(jKeyHandle); |
314 |
||
315 |
rv = (*ckpFunctions->C_SignRecoverInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); |
|
316 |
||
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
|
317 |
if (ckMechanism.pParameter != NULL_PTR) { |
2 | 318 |
free(ckMechanism.pParameter); |
319 |
} |
|
320 |
||
321 |
if(ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
|
322 |
} |
|
323 |
#endif |
|
324 |
||
325 |
#ifdef P11_ENABLE_C_SIGNRECOVER |
|
326 |
/* |
|
327 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
328 |
* Method: C_SignRecover |
|
329 |
* Signature: (J[BII[BII)I |
|
330 |
* Parametermapping: *PKCS11* |
|
331 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
332 |
* @param jbyteArray jData CK_BYTE_PTR pData |
|
333 |
* CK_ULONG ulDataLen |
|
334 |
* @return jbyteArray jSignature CK_BYTE_PTR pSignature |
|
335 |
* CK_ULONG_PTR pulSignatureLen |
|
336 |
*/ |
|
337 |
JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1SignRecover |
|
338 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jIn, jint jInOfs, jint jInLen, jbyteArray jOut, jint jOutOfs, jint jOutLen) |
|
339 |
{ |
|
340 |
CK_SESSION_HANDLE ckSessionHandle; |
|
341 |
CK_RV rv; |
|
342 |
CK_BYTE INBUF[MAX_STACK_BUFFER_LEN]; |
|
343 |
CK_BYTE OUTBUF[MAX_STACK_BUFFER_LEN]; |
|
344 |
CK_BYTE_PTR inBufP; |
|
345 |
CK_BYTE_PTR outBufP = OUTBUF; |
|
346 |
CK_ULONG ckSignatureLength = MAX_STACK_BUFFER_LEN; |
|
347 |
||
348 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
349 |
if (ckpFunctions == NULL) { return 0; } |
|
350 |
||
351 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
352 |
||
353 |
if (jInLen <= MAX_STACK_BUFFER_LEN) { |
|
354 |
inBufP = INBUF; |
|
355 |
} else { |
|
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
|
356 |
inBufP = (CK_BYTE_PTR) malloc((size_t)jInLen); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
357 |
if (inBufP == 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
|
358 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
359 |
return 0; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
360 |
} |
2 | 361 |
} |
362 |
||
363 |
(*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP); |
|
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
|
364 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
365 |
if (inBufP != INBUF) { free(inBufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
366 |
return 0; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
367 |
} |
2 | 368 |
rv = (*ckpFunctions->C_SignRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckSignatureLength); |
369 |
/* re-alloc larger buffer if it fits into our Java buffer */ |
|
370 |
if ((rv == CKR_BUFFER_TOO_SMALL) && (ckSignatureLength <= jIntToCKULong(jOutLen))) { |
|
371 |
outBufP = (CK_BYTE_PTR) malloc(ckSignatureLength); |
|
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
|
372 |
if (outBufP == 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
|
373 |
if (inBufP != INBUF) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
374 |
free(inBufP); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
375 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
376 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
377 |
return 0; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
378 |
} |
2 | 379 |
rv = (*ckpFunctions->C_SignRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckSignatureLength); |
380 |
} |
|
381 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
|
382 |
(*env)->SetByteArrayRegion(env, jOut, jOutOfs, ckSignatureLength, (jbyte *)outBufP); |
|
383 |
} |
|
384 |
||
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
|
385 |
if (inBufP != INBUF) { free(inBufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
386 |
if (outBufP != OUTBUF) { free(outBufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
387 |
|
2 | 388 |
return ckSignatureLength; |
389 |
} |
|
390 |
#endif |
|
391 |
||
392 |
#ifdef P11_ENABLE_C_VERIFYINIT |
|
393 |
/* |
|
394 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
395 |
* Method: C_VerifyInit |
|
396 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V |
|
397 |
* Parametermapping: *PKCS11* |
|
398 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
399 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
400 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE hKey |
|
401 |
*/ |
|
402 |
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyInit |
|
403 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jKeyHandle) |
|
404 |
{ |
|
405 |
CK_SESSION_HANDLE ckSessionHandle; |
|
406 |
CK_MECHANISM ckMechanism; |
|
407 |
CK_OBJECT_HANDLE ckKeyHandle; |
|
408 |
CK_RV rv; |
|
409 |
||
410 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
411 |
if (ckpFunctions == NULL) { return; } |
|
412 |
||
413 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
414 |
jMechanismToCKMechanism(env, jMechanism, &ckMechanism); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
415 |
if ((*env)->ExceptionCheck(env)) { return; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
416 |
|
2 | 417 |
ckKeyHandle = jLongToCKULong(jKeyHandle); |
418 |
||
419 |
rv = (*ckpFunctions->C_VerifyInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); |
|
420 |
||
421 |
if(ckMechanism.pParameter != NULL_PTR) { |
|
422 |
free(ckMechanism.pParameter); |
|
423 |
} |
|
424 |
||
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
|
425 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
2 | 426 |
} |
427 |
#endif |
|
428 |
||
429 |
#ifdef P11_ENABLE_C_VERIFY |
|
430 |
/* |
|
431 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
432 |
* Method: C_Verify |
|
433 |
* Signature: (J[B[B)V |
|
434 |
* Parametermapping: *PKCS11* |
|
435 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
436 |
* @param jbyteArray jData CK_BYTE_PTR pData |
|
437 |
* CK_ULONG ulDataLen |
|
438 |
* @param jbyteArray jSignature CK_BYTE_PTR pSignature |
|
439 |
* CK_ULONG_PTR pulSignatureLen |
|
440 |
*/ |
|
441 |
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1Verify |
|
442 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jData, jbyteArray jSignature) |
|
443 |
{ |
|
444 |
CK_SESSION_HANDLE ckSessionHandle; |
|
445 |
CK_BYTE_PTR ckpData = NULL_PTR; |
|
446 |
CK_BYTE_PTR ckpSignature = NULL_PTR; |
|
447 |
CK_ULONG ckDataLength; |
|
448 |
CK_ULONG ckSignatureLength; |
|
449 |
CK_RV rv; |
|
450 |
||
451 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
452 |
if (ckpFunctions == NULL) { return; } |
|
453 |
||
454 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
455 |
jByteArrayToCKByteArray(env, jData, &ckpData, &ckDataLength); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
456 |
if ((*env)->ExceptionCheck(env)) { return; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
457 |
|
2 | 458 |
jByteArrayToCKByteArray(env, jSignature, &ckpSignature, &ckSignatureLength); |
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
|
459 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
460 |
free(ckpData); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
461 |
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
|
462 |
} |
2 | 463 |
|
464 |
/* verify the signature */ |
|
465 |
rv = (*ckpFunctions->C_Verify)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, ckSignatureLength); |
|
466 |
||
467 |
free(ckpData); |
|
468 |
free(ckpSignature); |
|
469 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
470 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
2 | 471 |
} |
472 |
#endif |
|
473 |
||
474 |
#ifdef P11_ENABLE_C_VERIFYUPDATE |
|
475 |
/* |
|
476 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
477 |
* Method: C_VerifyUpdate |
|
478 |
* Signature: (J[BII)V |
|
479 |
* Parametermapping: *PKCS11* |
|
480 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
481 |
* @param jbyteArray jPart CK_BYTE_PTR pPart |
|
482 |
* CK_ULONG ulPartLen |
|
483 |
*/ |
|
484 |
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyUpdate |
|
485 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen) |
|
486 |
{ |
|
487 |
CK_SESSION_HANDLE ckSessionHandle; |
|
488 |
CK_RV rv; |
|
489 |
CK_BYTE_PTR bufP; |
|
490 |
CK_BYTE BUF[MAX_STACK_BUFFER_LEN]; |
|
491 |
jsize bufLen; |
|
492 |
||
493 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
494 |
if (ckpFunctions == NULL) { return; } |
|
495 |
||
496 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
497 |
||
498 |
if (directIn != 0) { |
|
499 |
rv = (*ckpFunctions->C_VerifyUpdate)(ckSessionHandle, (CK_BYTE_PTR)directIn, jInLen); |
|
500 |
ckAssertReturnValueOK(env, rv); |
|
501 |
return; |
|
502 |
} |
|
503 |
||
504 |
if (jInLen <= MAX_STACK_BUFFER_LEN) { |
|
505 |
bufLen = MAX_STACK_BUFFER_LEN; |
|
506 |
bufP = BUF; |
|
507 |
} else { |
|
508 |
bufLen = min(MAX_HEAP_BUFFER_LEN, jInLen); |
|
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
|
509 |
bufP = (CK_BYTE_PTR) malloc((size_t)bufLen); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
510 |
if (bufP == 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
|
511 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
512 |
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
|
513 |
} |
2 | 514 |
} |
515 |
||
516 |
while (jInLen > 0) { |
|
517 |
jsize chunkLen = min(bufLen, jInLen); |
|
518 |
(*env)->GetByteArrayRegion(env, jIn, jInOfs, chunkLen, (jbyte *)bufP); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
519 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
520 |
if (bufP != BUF) { free(bufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
521 |
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
|
522 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
523 |
|
2 | 524 |
rv = (*ckpFunctions->C_VerifyUpdate)(ckSessionHandle, bufP, chunkLen); |
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
|
525 |
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
|
526 |
if (bufP != BUF) { free(bufP); } |
2 | 527 |
return; |
528 |
} |
|
529 |
jInOfs += chunkLen; |
|
530 |
jInLen -= chunkLen; |
|
531 |
} |
|
532 |
||
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
|
533 |
if (bufP != BUF) { free(bufP); } |
2 | 534 |
} |
535 |
#endif |
|
536 |
||
537 |
#ifdef P11_ENABLE_C_VERIFYFINAL |
|
538 |
/* |
|
539 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
540 |
* Method: C_VerifyFinal |
|
541 |
* Signature: (J[B)V |
|
542 |
* Parametermapping: *PKCS11* |
|
543 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
544 |
* @param jbyteArray jSignature CK_BYTE_PTR pSignature |
|
545 |
* CK_ULONG ulSignatureLen |
|
546 |
*/ |
|
547 |
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyFinal |
|
548 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jSignature) |
|
549 |
{ |
|
550 |
CK_SESSION_HANDLE ckSessionHandle; |
|
551 |
CK_BYTE_PTR ckpSignature = NULL_PTR; |
|
552 |
CK_ULONG ckSignatureLength; |
|
553 |
CK_RV rv; |
|
554 |
||
555 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
556 |
if (ckpFunctions == NULL) { return; } |
|
557 |
||
558 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
559 |
jByteArrayToCKByteArray(env, jSignature, &ckpSignature, &ckSignatureLength); |
|
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
|
560 |
if ((*env)->ExceptionCheck(env)) { return; } |
2 | 561 |
|
562 |
/* verify the signature */ |
|
563 |
rv = (*ckpFunctions->C_VerifyFinal)(ckSessionHandle, ckpSignature, ckSignatureLength); |
|
564 |
||
565 |
free(ckpSignature); |
|
566 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
567 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
2 | 568 |
} |
569 |
#endif |
|
570 |
||
571 |
#ifdef P11_ENABLE_C_VERIFYRECOVERINIT |
|
572 |
/* |
|
573 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
574 |
* Method: C_VerifyRecoverInit |
|
575 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V |
|
576 |
* Parametermapping: *PKCS11* |
|
577 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
578 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
579 |
* @return jlong jKeyHandle CK_OBJECT_HANDLE hKey |
|
580 |
*/ |
|
581 |
JNIEXPORT void JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecoverInit |
|
582 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jKeyHandle) |
|
583 |
{ |
|
584 |
CK_SESSION_HANDLE ckSessionHandle; |
|
585 |
CK_MECHANISM ckMechanism; |
|
586 |
CK_OBJECT_HANDLE ckKeyHandle; |
|
587 |
CK_RV rv; |
|
588 |
||
589 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
590 |
if (ckpFunctions == NULL) { return; } |
|
591 |
||
592 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
593 |
jMechanismToCKMechanism(env, jMechanism, &ckMechanism); |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
594 |
if ((*env)->ExceptionCheck(env)) { return; } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
595 |
|
2 | 596 |
ckKeyHandle = jLongToCKULong(jKeyHandle); |
597 |
||
598 |
rv = (*ckpFunctions->C_VerifyRecoverInit)(ckSessionHandle, &ckMechanism, ckKeyHandle); |
|
599 |
||
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 (ckMechanism.pParameter != NULL_PTR) { |
2 | 601 |
free(ckMechanism.pParameter); |
602 |
} |
|
603 |
||
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
604 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
2 | 605 |
} |
606 |
#endif |
|
607 |
||
608 |
#ifdef P11_ENABLE_C_VERIFYRECOVER |
|
609 |
/* |
|
610 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
611 |
* Method: C_VerifyRecover |
|
612 |
* Signature: (J[BII[BII)I |
|
613 |
* Parametermapping: *PKCS11* |
|
614 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
615 |
* @param jbyteArray jSignature CK_BYTE_PTR pSignature |
|
616 |
* CK_ULONG ulSignatureLen |
|
617 |
* @return jbyteArray jData CK_BYTE_PTR pData |
|
618 |
* CK_ULONG_PTR pulDataLen |
|
619 |
*/ |
|
620 |
JNIEXPORT jint JNICALL Java_sun_security_pkcs11_wrapper_PKCS11_C_1VerifyRecover |
|
621 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jIn, jint jInOfs, jint jInLen, jbyteArray jOut, jint jOutOfs, jint jOutLen) |
|
622 |
{ |
|
623 |
CK_SESSION_HANDLE ckSessionHandle; |
|
624 |
CK_RV rv; |
|
625 |
CK_BYTE INBUF[MAX_STACK_BUFFER_LEN]; |
|
626 |
CK_BYTE OUTBUF[MAX_STACK_BUFFER_LEN]; |
|
627 |
CK_BYTE_PTR inBufP; |
|
628 |
CK_BYTE_PTR outBufP = OUTBUF; |
|
629 |
CK_ULONG ckDataLength = MAX_STACK_BUFFER_LEN; |
|
630 |
||
631 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
632 |
if (ckpFunctions == NULL) { return 0; } |
|
633 |
||
634 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
635 |
||
636 |
if (jInLen <= MAX_STACK_BUFFER_LEN) { |
|
637 |
inBufP = INBUF; |
|
638 |
} else { |
|
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
|
639 |
inBufP = (CK_BYTE_PTR) malloc((size_t)jInLen); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
640 |
if (inBufP == 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
|
641 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
642 |
return 0; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
643 |
} |
2 | 644 |
} |
645 |
||
646 |
(*env)->GetByteArrayRegion(env, jIn, jInOfs, jInLen, (jbyte *)inBufP); |
|
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
|
647 |
if ((*env)->ExceptionCheck(env)) { |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
648 |
if (inBufP != INBUF) { free(inBufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
649 |
return 0; |
9994f4f08a59
6812738: SSL 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 |
} |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
651 |
|
2 | 652 |
rv = (*ckpFunctions->C_VerifyRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckDataLength); |
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
|
653 |
|
2 | 654 |
/* re-alloc larger buffer if it fits into our Java buffer */ |
655 |
if ((rv == CKR_BUFFER_TOO_SMALL) && (ckDataLength <= jIntToCKULong(jOutLen))) { |
|
656 |
outBufP = (CK_BYTE_PTR) malloc(ckDataLength); |
|
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 |
if (outBufP == 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
|
658 |
if (inBufP != INBUF) { free(inBufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
659 |
JNU_ThrowOutOfMemoryError(env, 0); |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
660 |
return 0; |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
661 |
} |
2 | 662 |
rv = (*ckpFunctions->C_VerifyRecover)(ckSessionHandle, inBufP, jInLen, outBufP, &ckDataLength); |
663 |
} |
|
664 |
if (ckAssertReturnValueOK(env, rv) == CK_ASSERT_OK) { |
|
665 |
(*env)->SetByteArrayRegion(env, jOut, jOutOfs, ckDataLength, (jbyte *)outBufP); |
|
666 |
} |
|
667 |
||
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
|
668 |
if (inBufP != INBUF) { free(inBufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
669 |
if (outBufP != OUTBUF) { free(outBufP); } |
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
670 |
|
2 | 671 |
return ckDataLength; |
672 |
} |
|
673 |
#endif |