2
|
1 |
/*
|
|
2 |
* Portions Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
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 |
/*
|
|
49 |
* pkcs11wrapper.c
|
|
50 |
* 18.05.2001
|
|
51 |
*
|
|
52 |
* This is the implementation of the native functions of the Java to PKCS#11 interface.
|
|
53 |
* All function use some helper functions to convert the JNI types to PKCS#11 types.
|
|
54 |
*
|
|
55 |
* @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
|
|
56 |
* @author Martin Schlaeffer <schlaeff@sbox.tugraz.at>
|
|
57 |
*/
|
|
58 |
|
|
59 |
|
|
60 |
#include "pkcs11wrapper.h"
|
|
61 |
|
|
62 |
#include <stdio.h>
|
|
63 |
#include <stdlib.h>
|
|
64 |
#include <string.h>
|
|
65 |
#include <assert.h>
|
|
66 |
|
|
67 |
#include "sun_security_pkcs11_wrapper_PKCS11.h"
|
|
68 |
|
|
69 |
/* declare file private functions */
|
|
70 |
|
|
71 |
void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength);
|
|
72 |
|
|
73 |
|
|
74 |
/*
|
|
75 |
* converts a pointer to a CK_DATE structure into a Java CK_DATE Object.
|
|
76 |
*
|
|
77 |
* @param env - used to call JNI funktions to create the new Java object
|
|
78 |
* @param ckpValue - the pointer to the CK_DATE structure
|
|
79 |
* @return - the new Java CK_DATE object
|
|
80 |
*/
|
|
81 |
jobject ckDatePtrToJDateObject(JNIEnv *env, const CK_DATE *ckpDate)
|
|
82 |
{
|
|
83 |
jclass jDateClass;
|
|
84 |
jmethodID jCtrId;
|
|
85 |
jobject jDateObject;
|
|
86 |
jcharArray jYear;
|
|
87 |
jcharArray jMonth;
|
|
88 |
jcharArray jDay;
|
|
89 |
|
|
90 |
/* load CK_DATE class */
|
|
91 |
jDateClass = (*env)->FindClass(env, CLASS_DATE);
|
|
92 |
assert(jDateClass != 0);
|
|
93 |
|
|
94 |
/* load CK_DATE constructor */
|
|
95 |
jCtrId = (*env)->GetMethodID(env, jDateClass, "<init>", "([C[C[C)V");
|
|
96 |
assert(jCtrId != 0);
|
|
97 |
|
|
98 |
/* prep all fields */
|
|
99 |
jYear = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->year), 4);
|
|
100 |
jMonth = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->month), 2);
|
|
101 |
jDay = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->day), 2);
|
|
102 |
|
|
103 |
/* create new CK_DATE object */
|
|
104 |
jDateObject =
|
|
105 |
(*env)->NewObject(env, jDateClass, jCtrId, jYear, jMonth, jDay);
|
|
106 |
assert(jDateObject != 0);
|
|
107 |
|
|
108 |
/* free local references */
|
|
109 |
(*env)->DeleteLocalRef(env, jDateClass);
|
|
110 |
(*env)->DeleteLocalRef(env, jYear);
|
|
111 |
(*env)->DeleteLocalRef(env, jMonth);
|
|
112 |
(*env)->DeleteLocalRef(env, jDay);
|
|
113 |
|
|
114 |
return jDateObject ;
|
|
115 |
}
|
|
116 |
|
|
117 |
/*
|
|
118 |
* converts a pointer to a CK_VERSION structure into a Java CK_VERSION Object.
|
|
119 |
*
|
|
120 |
* @param env - used to call JNI funktions to create the new Java object
|
|
121 |
* @param ckpVersion - the pointer to the CK_VERSION structure
|
|
122 |
* @return - the new Java CK_VERSION object
|
|
123 |
*/
|
|
124 |
jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion)
|
|
125 |
{
|
|
126 |
jclass jVersionClass;
|
|
127 |
jmethodID jCtrId;
|
|
128 |
jobject jVersionObject;
|
|
129 |
jint jMajor;
|
|
130 |
jint jMinor;
|
|
131 |
|
|
132 |
/* load CK_VERSION class */
|
|
133 |
jVersionClass = (*env)->FindClass(env, CLASS_VERSION);
|
|
134 |
assert(jVersionClass != 0);
|
|
135 |
|
|
136 |
/* load CK_VERSION constructor */
|
|
137 |
jCtrId = (*env)->GetMethodID(env, jVersionClass, "<init>", "(II)V");
|
|
138 |
assert(jCtrId != 0);
|
|
139 |
|
|
140 |
/* prep both fields */
|
|
141 |
jMajor = ckpVersion->major;
|
|
142 |
jMinor = ckpVersion->minor;
|
|
143 |
|
|
144 |
/* create new CK_VERSION object */
|
|
145 |
jVersionObject =
|
|
146 |
(*env)->NewObject(env, jVersionClass, jCtrId, jMajor, jMinor);
|
|
147 |
assert(jVersionObject != 0);
|
|
148 |
|
|
149 |
/* free local references */
|
|
150 |
(*env)->DeleteLocalRef(env, jVersionClass);
|
|
151 |
|
|
152 |
return jVersionObject ;
|
|
153 |
}
|
|
154 |
|
|
155 |
/*
|
|
156 |
* converts a pointer to a CK_SESSION_INFO structure into a Java CK_SESSION_INFO Object.
|
|
157 |
*
|
|
158 |
* @param env - used to call JNI funktions to create the new Java object
|
|
159 |
* @param ckpSessionInfo - the pointer to the CK_SESSION_INFO structure
|
|
160 |
* @return - the new Java CK_SESSION_INFO object
|
|
161 |
*/
|
|
162 |
jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ckpSessionInfo)
|
|
163 |
{
|
|
164 |
jclass jSessionInfoClass;
|
|
165 |
jmethodID jCtrId;
|
|
166 |
jobject jSessionInfoObject;
|
|
167 |
jlong jSlotID;
|
|
168 |
jlong jState;
|
|
169 |
jlong jFlags;
|
|
170 |
jlong jDeviceError;
|
|
171 |
|
|
172 |
/* load CK_SESSION_INFO class */
|
|
173 |
jSessionInfoClass = (*env)->FindClass(env, CLASS_SESSION_INFO);
|
|
174 |
assert(jSessionInfoClass != 0);
|
|
175 |
|
|
176 |
/* load CK_SESSION_INFO constructor */
|
|
177 |
jCtrId = (*env)->GetMethodID(env, jSessionInfoClass, "<init>", "(JJJJ)V");
|
|
178 |
assert(jCtrId != 0);
|
|
179 |
|
|
180 |
/* prep all fields */
|
|
181 |
jSlotID = ckULongToJLong(ckpSessionInfo->slotID);
|
|
182 |
jState = ckULongToJLong(ckpSessionInfo->state);
|
|
183 |
jFlags = ckULongToJLong(ckpSessionInfo->flags);
|
|
184 |
jDeviceError = ckULongToJLong(ckpSessionInfo->ulDeviceError);
|
|
185 |
|
|
186 |
/* create new CK_SESSION_INFO object */
|
|
187 |
jSessionInfoObject =
|
|
188 |
(*env)->NewObject(env, jSessionInfoClass, jCtrId, jSlotID, jState,
|
|
189 |
jFlags, jDeviceError);
|
|
190 |
assert(jSessionInfoObject != 0);
|
|
191 |
|
|
192 |
/* free local references */
|
|
193 |
(*env)->DeleteLocalRef(env, jSessionInfoClass);
|
|
194 |
|
|
195 |
return jSessionInfoObject ;
|
|
196 |
}
|
|
197 |
|
|
198 |
/*
|
|
199 |
* converts a pointer to a CK_ATTRIBUTE structure into a Java CK_ATTRIBUTE Object.
|
|
200 |
*
|
|
201 |
* @param env - used to call JNI funktions to create the new Java object
|
|
202 |
* @param ckpAttribute - the pointer to the CK_ATTRIBUTE structure
|
|
203 |
* @return - the new Java CK_ATTRIBUTE object
|
|
204 |
*/
|
|
205 |
jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute)
|
|
206 |
{
|
|
207 |
jclass jAttributeClass;
|
|
208 |
jmethodID jCtrId;
|
|
209 |
jobject jAttributeObject;
|
|
210 |
jlong jType;
|
|
211 |
jobject jPValue = NULL;
|
|
212 |
|
|
213 |
jAttributeClass = (*env)->FindClass(env, CLASS_ATTRIBUTE);
|
|
214 |
assert(jAttributeClass != 0);
|
|
215 |
|
|
216 |
/* load CK_INFO constructor */
|
|
217 |
jCtrId = (*env)->GetMethodID(env, jAttributeClass, "<init>", "(JLjava/lang/Object;)V");
|
|
218 |
assert(jCtrId != 0);
|
|
219 |
|
|
220 |
/* prep both fields */
|
|
221 |
jType = ckULongToJLong(ckpAttribute->type);
|
|
222 |
jPValue = ckAttributeValueToJObject(env, ckpAttribute);
|
|
223 |
|
|
224 |
/* create new CK_ATTRIBUTE object */
|
|
225 |
jAttributeObject =
|
|
226 |
(*env)->NewObject(env, jAttributeClass, jCtrId, jType, jPValue);
|
|
227 |
assert(jAttributeObject != 0);
|
|
228 |
|
|
229 |
/* free local references */
|
|
230 |
(*env)->DeleteLocalRef(env, jAttributeClass);
|
|
231 |
(*env)->DeleteLocalRef(env, jPValue);
|
|
232 |
|
|
233 |
return jAttributeObject;
|
|
234 |
}
|
|
235 |
|
|
236 |
|
|
237 |
/*
|
|
238 |
* converts a Java CK_VERSION object into a pointer to a CK_VERSION structure
|
|
239 |
*
|
|
240 |
* @param env - used to call JNI funktions to get the values out of the Java object
|
|
241 |
* @param jVersion - the Java CK_VERSION object to convert
|
|
242 |
* @return - the pointer to the new CK_VERSION structure
|
|
243 |
*/
|
|
244 |
CK_VERSION_PTR jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion)
|
|
245 |
{
|
|
246 |
CK_VERSION_PTR ckpVersion;
|
|
247 |
jclass jVersionClass;
|
|
248 |
jfieldID jFieldID;
|
|
249 |
jbyte jMajor, jMinor;
|
|
250 |
|
|
251 |
if (jVersion == NULL) {
|
|
252 |
return NULL;
|
|
253 |
}
|
|
254 |
|
|
255 |
/* allocate memory for CK_VERSION pointer */
|
|
256 |
ckpVersion = (CK_VERSION_PTR) malloc(sizeof(CK_VERSION));
|
|
257 |
|
|
258 |
/* get CK_VERSION class */
|
|
259 |
jVersionClass = (*env)->GetObjectClass(env, jVersion);
|
|
260 |
assert(jVersionClass != 0);
|
|
261 |
|
|
262 |
/* get Major */
|
|
263 |
jFieldID = (*env)->GetFieldID(env, jVersionClass, "major", "B");
|
|
264 |
assert(jFieldID != 0);
|
|
265 |
jMajor = (*env)->GetByteField(env, jVersion, jFieldID);
|
|
266 |
ckpVersion->major = jByteToCKByte(jMajor);
|
|
267 |
|
|
268 |
/* get Minor */
|
|
269 |
jFieldID = (*env)->GetFieldID(env, jVersionClass, "minor", "B");
|
|
270 |
assert(jFieldID != 0);
|
|
271 |
jMinor = (*env)->GetByteField(env, jVersion, jFieldID);
|
|
272 |
ckpVersion->minor = jByteToCKByte(jMinor);
|
|
273 |
|
|
274 |
return ckpVersion ;
|
|
275 |
}
|
|
276 |
|
|
277 |
|
|
278 |
/*
|
|
279 |
* converts a Java CK_DATE object into a pointer to a CK_DATE structure
|
|
280 |
*
|
|
281 |
* @param env - used to call JNI funktions to get the values out of the Java object
|
|
282 |
* @param jVersion - the Java CK_DATE object to convert
|
|
283 |
* @return - the pointer to the new CK_DATE structure
|
|
284 |
*/
|
|
285 |
CK_DATE * jDateObjectPtrToCKDatePtr(JNIEnv *env, jobject jDate)
|
|
286 |
{
|
|
287 |
CK_DATE * ckpDate;
|
|
288 |
CK_ULONG ckLength;
|
|
289 |
jclass jDateClass;
|
|
290 |
jfieldID jFieldID;
|
|
291 |
jobject jYear, jMonth, jDay;
|
|
292 |
jchar *jTempChars;
|
|
293 |
CK_ULONG i;
|
|
294 |
|
|
295 |
/* allocate memory for CK_DATE pointer */
|
|
296 |
ckpDate = (CK_DATE *) malloc(sizeof(CK_DATE));
|
|
297 |
|
|
298 |
/* get CK_DATE class */
|
|
299 |
jDateClass = (*env)->FindClass(env, CLASS_DATE);
|
|
300 |
assert(jDateClass != 0);
|
|
301 |
|
|
302 |
/* get Year */
|
|
303 |
jFieldID = (*env)->GetFieldID(env, jDateClass, "year", "[C");
|
|
304 |
assert(jFieldID != 0);
|
|
305 |
jYear = (*env)->GetObjectField(env, jDate, jFieldID);
|
|
306 |
|
|
307 |
if (jYear == NULL) {
|
|
308 |
ckpDate->year[0] = 0;
|
|
309 |
ckpDate->year[1] = 0;
|
|
310 |
ckpDate->year[2] = 0;
|
|
311 |
ckpDate->year[3] = 0;
|
|
312 |
} else {
|
|
313 |
ckLength = (*env)->GetArrayLength(env, jYear);
|
|
314 |
jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar));
|
|
315 |
(*env)->GetCharArrayRegion(env, jYear, 0, ckLength, jTempChars);
|
|
316 |
for (i = 0; (i < ckLength) && (i < 4) ; i++) {
|
|
317 |
ckpDate->year[i] = jCharToCKChar(jTempChars[i]);
|
|
318 |
}
|
|
319 |
free(jTempChars);
|
|
320 |
}
|
|
321 |
|
|
322 |
/* get Month */
|
|
323 |
jFieldID = (*env)->GetFieldID(env, jDateClass, "month", "[C");
|
|
324 |
assert(jFieldID != 0);
|
|
325 |
jMonth = (*env)->GetObjectField(env, jDate, jFieldID);
|
|
326 |
|
|
327 |
if (jMonth == NULL) {
|
|
328 |
ckpDate->month[0] = 0;
|
|
329 |
ckpDate->month[1] = 0;
|
|
330 |
} else {
|
|
331 |
ckLength = (*env)->GetArrayLength(env, jMonth);
|
|
332 |
jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar));
|
|
333 |
(*env)->GetCharArrayRegion(env, jMonth, 0, ckLength, jTempChars);
|
|
334 |
for (i = 0; (i < ckLength) && (i < 4) ; i++) {
|
|
335 |
ckpDate->month[i] = jCharToCKChar(jTempChars[i]);
|
|
336 |
}
|
|
337 |
free(jTempChars);
|
|
338 |
}
|
|
339 |
|
|
340 |
/* get Day */
|
|
341 |
jFieldID = (*env)->GetFieldID(env, jDateClass, "day", "[C");
|
|
342 |
assert(jFieldID != 0);
|
|
343 |
jDay = (*env)->GetObjectField(env, jDate, jFieldID);
|
|
344 |
|
|
345 |
if (jDay == NULL) {
|
|
346 |
ckpDate->day[0] = 0;
|
|
347 |
ckpDate->day[1] = 0;
|
|
348 |
} else {
|
|
349 |
ckLength = (*env)->GetArrayLength(env, jDay);
|
|
350 |
jTempChars = (jchar*) malloc((ckLength) * sizeof(jchar));
|
|
351 |
(*env)->GetCharArrayRegion(env, jDay, 0, ckLength, jTempChars);
|
|
352 |
for (i = 0; (i < ckLength) && (i < 4) ; i++) {
|
|
353 |
ckpDate->day[i] = jCharToCKChar(jTempChars[i]);
|
|
354 |
}
|
|
355 |
free(jTempChars);
|
|
356 |
}
|
|
357 |
|
|
358 |
return ckpDate ;
|
|
359 |
}
|
|
360 |
|
|
361 |
|
|
362 |
/*
|
|
363 |
* converts a Java CK_ATTRIBUTE object into a CK_ATTRIBUTE structure
|
|
364 |
*
|
|
365 |
* @param env - used to call JNI funktions to get the values out of the Java object
|
|
366 |
* @param jAttribute - the Java CK_ATTRIBUTE object to convert
|
|
367 |
* @return - the new CK_ATTRIBUTE structure
|
|
368 |
*/
|
|
369 |
CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute)
|
|
370 |
{
|
|
371 |
CK_ATTRIBUTE ckAttribute;
|
|
372 |
jclass jAttributeClass;
|
|
373 |
jfieldID jFieldID;
|
|
374 |
jlong jType;
|
|
375 |
jobject jPValue;
|
|
376 |
|
|
377 |
TRACE0("\nDEBUG: jAttributeToCKAttribute");
|
|
378 |
/* get CK_ATTRIBUTE class */
|
|
379 |
TRACE0(", getting attribute object class");
|
|
380 |
jAttributeClass = (*env)->GetObjectClass(env, jAttribute);
|
|
381 |
assert(jAttributeClass != 0);
|
|
382 |
|
|
383 |
/* get type */
|
|
384 |
TRACE0(", getting type field");
|
|
385 |
jFieldID = (*env)->GetFieldID(env, jAttributeClass, "type", "J");
|
|
386 |
assert(jFieldID != 0);
|
|
387 |
jType = (*env)->GetLongField(env, jAttribute, jFieldID);
|
|
388 |
TRACE1(", type=0x%X", jType);
|
|
389 |
|
|
390 |
/* get pValue */
|
|
391 |
TRACE0(", getting pValue field");
|
|
392 |
jFieldID = (*env)->GetFieldID(env, jAttributeClass, "pValue", "Ljava/lang/Object;");
|
|
393 |
assert(jFieldID != 0);
|
|
394 |
jPValue = (*env)->GetObjectField(env, jAttribute, jFieldID);
|
|
395 |
TRACE1(", pValue=%p", jPValue);
|
|
396 |
|
|
397 |
ckAttribute.type = jLongToCKULong(jType);
|
|
398 |
TRACE0(", converting pValue to primitive object");
|
|
399 |
|
|
400 |
/* convert the Java pValue object to a CK-type pValue pointer */
|
|
401 |
jObjectToPrimitiveCKObjectPtrPtr(env, jPValue, &(ckAttribute.pValue), &(ckAttribute.ulValueLen));
|
|
402 |
|
|
403 |
TRACE0("\nFINISHED\n");
|
|
404 |
|
|
405 |
return ckAttribute ;
|
|
406 |
}
|
|
407 |
|
|
408 |
/*
|
|
409 |
* converts the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to a
|
|
410 |
* CK_SSL3_MASTER_KEY_DERIVE_PARAMS structure
|
|
411 |
*
|
|
412 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
413 |
* @param jParam - the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to convert
|
|
414 |
* @return - the new CK_SSL3_MASTER_KEY_DERIVE_PARAMS structure
|
|
415 |
*/
|
|
416 |
CK_SSL3_MASTER_KEY_DERIVE_PARAMS jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(JNIEnv *env, jobject jParam)
|
|
417 |
{
|
|
418 |
// XXX don't return structs
|
|
419 |
// XXX prefetch class and field ids
|
|
420 |
jclass jSsl3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS);
|
|
421 |
CK_SSL3_MASTER_KEY_DERIVE_PARAMS ckParam;
|
|
422 |
jfieldID fieldID;
|
|
423 |
jobject jObject;
|
|
424 |
jclass jSsl3RandomDataClass;
|
|
425 |
jobject jRandomInfo;
|
|
426 |
|
|
427 |
/* get RandomInfo */
|
|
428 |
jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA);
|
|
429 |
fieldID = (*env)->GetFieldID(env, jSsl3MasterKeyDeriveParamsClass, "RandomInfo", "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
|
|
430 |
assert(fieldID != 0);
|
|
431 |
jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
|
|
432 |
|
|
433 |
/* get pClientRandom and ulClientRandomLength out of RandomInfo */
|
|
434 |
fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B");
|
|
435 |
assert(fieldID != 0);
|
|
436 |
jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID);
|
|
437 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen));
|
|
438 |
|
|
439 |
/* get pServerRandom and ulServerRandomLength out of RandomInfo */
|
|
440 |
fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B");
|
|
441 |
assert(fieldID != 0);
|
|
442 |
jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID);
|
|
443 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen));
|
|
444 |
|
|
445 |
/* get pVersion */
|
|
446 |
fieldID = (*env)->GetFieldID(env, jSsl3MasterKeyDeriveParamsClass, "pVersion", "Lsun/security/pkcs11/wrapper/CK_VERSION;");
|
|
447 |
assert(fieldID != 0);
|
|
448 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
449 |
ckParam.pVersion = jVersionToCKVersionPtr(env, jObject);
|
|
450 |
|
|
451 |
return ckParam ;
|
|
452 |
}
|
|
453 |
|
|
454 |
|
|
455 |
/*
|
|
456 |
* converts the Java CK_TLS_PRF_PARAMS object to a CK_TLS_PRF_PARAMS structure
|
|
457 |
*/
|
|
458 |
CK_TLS_PRF_PARAMS jTlsPrfParamsToCKTlsPrfParam(JNIEnv *env, jobject jParam)
|
|
459 |
{
|
|
460 |
jclass jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS);
|
|
461 |
CK_TLS_PRF_PARAMS ckParam;
|
|
462 |
jfieldID fieldID;
|
|
463 |
jobject jObject;
|
|
464 |
|
|
465 |
fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pSeed", "[B");
|
|
466 |
assert(fieldID != 0);
|
|
467 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
468 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pSeed), &(ckParam.ulSeedLen));
|
|
469 |
|
|
470 |
fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pLabel", "[B");
|
|
471 |
assert(fieldID != 0);
|
|
472 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
473 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pLabel), &(ckParam.ulLabelLen));
|
|
474 |
|
|
475 |
ckParam.pulOutputLen = malloc(sizeof(CK_ULONG));
|
|
476 |
|
|
477 |
fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pOutput", "[B");
|
|
478 |
assert(fieldID != 0);
|
|
479 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
480 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pOutput), ckParam.pulOutputLen);
|
|
481 |
|
|
482 |
return ckParam ;
|
|
483 |
}
|
|
484 |
|
|
485 |
/*
|
|
486 |
* converts the Java CK_SSL3_KEY_MAT_PARAMS object to a CK_SSL3_KEY_MAT_PARAMS structure
|
|
487 |
*
|
|
488 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
489 |
* @param jParam - the Java CK_SSL3_KEY_MAT_PARAMS object to convert
|
|
490 |
* @return - the new CK_SSL3_KEY_MAT_PARAMS structure
|
|
491 |
*/
|
|
492 |
CK_SSL3_KEY_MAT_PARAMS jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject jParam)
|
|
493 |
{
|
|
494 |
// XXX don't return structs
|
|
495 |
// XXX prefetch class and field ids
|
|
496 |
jclass jSsl3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS);
|
|
497 |
CK_SSL3_KEY_MAT_PARAMS ckParam;
|
|
498 |
jfieldID fieldID;
|
|
499 |
jlong jLong;
|
|
500 |
jboolean jBoolean;
|
|
501 |
jobject jObject;
|
|
502 |
jobject jRandomInfo;
|
|
503 |
jobject jReturnedKeyMaterial;
|
|
504 |
jclass jSsl3RandomDataClass;
|
|
505 |
jclass jSsl3KeyMatOutClass;
|
|
506 |
CK_ULONG ckTemp;
|
|
507 |
|
|
508 |
/* get ulMacSizeInBits */
|
|
509 |
fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulMacSizeInBits", "J");
|
|
510 |
assert(fieldID != 0);
|
|
511 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
512 |
ckParam.ulMacSizeInBits = jLongToCKULong(jLong);
|
|
513 |
|
|
514 |
/* get ulKeySizeInBits */
|
|
515 |
fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulKeySizeInBits", "J");
|
|
516 |
assert(fieldID != 0);
|
|
517 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
518 |
ckParam.ulKeySizeInBits = jLongToCKULong(jLong);
|
|
519 |
|
|
520 |
/* get ulIVSizeInBits */
|
|
521 |
fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "ulIVSizeInBits", "J");
|
|
522 |
assert(fieldID != 0);
|
|
523 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
524 |
ckParam.ulIVSizeInBits = jLongToCKULong(jLong);
|
|
525 |
|
|
526 |
/* get bIsExport */
|
|
527 |
fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "bIsExport", "Z");
|
|
528 |
assert(fieldID != 0);
|
|
529 |
jBoolean = (*env)->GetBooleanField(env, jParam, fieldID);
|
|
530 |
ckParam.bIsExport = jBooleanToCKBBool(jBoolean);
|
|
531 |
|
|
532 |
/* get RandomInfo */
|
|
533 |
jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA);
|
|
534 |
fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "RandomInfo", "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
|
|
535 |
assert(fieldID != 0);
|
|
536 |
jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
|
|
537 |
|
|
538 |
/* get pClientRandom and ulClientRandomLength out of RandomInfo */
|
|
539 |
fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B");
|
|
540 |
assert(fieldID != 0);
|
|
541 |
jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID);
|
|
542 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pClientRandom), &(ckParam.RandomInfo.ulClientRandomLen));
|
|
543 |
|
|
544 |
/* get pServerRandom and ulServerRandomLength out of RandomInfo */
|
|
545 |
fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B");
|
|
546 |
assert(fieldID != 0);
|
|
547 |
jObject = (*env)->GetObjectField(env, jRandomInfo, fieldID);
|
|
548 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.RandomInfo.pServerRandom), &(ckParam.RandomInfo.ulServerRandomLen));
|
|
549 |
|
|
550 |
/* get pReturnedKeyMaterial */
|
|
551 |
jSsl3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT);
|
|
552 |
fieldID = (*env)->GetFieldID(env, jSsl3KeyMatParamsClass, "pReturnedKeyMaterial", "Lsun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT;");
|
|
553 |
assert(fieldID != 0);
|
|
554 |
jReturnedKeyMaterial = (*env)->GetObjectField(env, jParam, fieldID);
|
|
555 |
|
|
556 |
/* allocate memory for pRetrunedKeyMaterial */
|
|
557 |
ckParam.pReturnedKeyMaterial = (CK_SSL3_KEY_MAT_OUT_PTR) malloc(sizeof(CK_SSL3_KEY_MAT_OUT));
|
|
558 |
|
|
559 |
// the handles are output params only, no need to fetch them from Java
|
|
560 |
ckParam.pReturnedKeyMaterial->hClientMacSecret = 0;
|
|
561 |
ckParam.pReturnedKeyMaterial->hServerMacSecret = 0;
|
|
562 |
ckParam.pReturnedKeyMaterial->hClientKey = 0;
|
|
563 |
ckParam.pReturnedKeyMaterial->hServerKey = 0;
|
|
564 |
|
|
565 |
/* get pIVClient out of pReturnedKeyMaterial */
|
|
566 |
fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVClient", "[B");
|
|
567 |
assert(fieldID != 0);
|
|
568 |
jObject = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID);
|
|
569 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pReturnedKeyMaterial->pIVClient), &ckTemp);
|
|
570 |
|
|
571 |
/* get pIVServer out of pReturnedKeyMaterial */
|
|
572 |
fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVServer", "[B");
|
|
573 |
assert(fieldID != 0);
|
|
574 |
jObject = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID);
|
|
575 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pReturnedKeyMaterial->pIVServer), &ckTemp);
|
|
576 |
|
|
577 |
return ckParam ;
|
|
578 |
}
|
|
579 |
|
|
580 |
/*
|
|
581 |
* converts a Java CK_MECHANISM object into a CK_MECHANISM structure
|
|
582 |
*
|
|
583 |
* @param env - used to call JNI funktions to get the values out of the Java object
|
|
584 |
* @param jMechanism - the Java CK_MECHANISM object to convert
|
|
585 |
* @return - the new CK_MECHANISM structure
|
|
586 |
*/
|
|
587 |
void jMechanismToCKMechanism(JNIEnv *env, jobject jMechanism, CK_MECHANISM_PTR ckMechanismPtr)
|
|
588 |
{
|
|
589 |
jlong jMechanismType = (*env)->GetLongField(env, jMechanism, mech_mechanismID);
|
|
590 |
jobject jParameter = (*env)->GetObjectField(env, jMechanism, mech_pParameterID);
|
|
591 |
|
|
592 |
(*ckMechanismPtr).mechanism = jLongToCKULong(jMechanismType);
|
|
593 |
|
|
594 |
/* convert the specific Java mechanism parameter object to a pointer to a CK-type mechanism
|
|
595 |
* structure
|
|
596 |
*/
|
|
597 |
if (jParameter == NULL) {
|
|
598 |
(*ckMechanismPtr).pParameter = NULL;
|
|
599 |
(*ckMechanismPtr).ulParameterLen = 0;
|
|
600 |
} else {
|
|
601 |
jMechanismParameterToCKMechanismParameter(env, jParameter, &(*ckMechanismPtr).pParameter, &(*ckMechanismPtr).ulParameterLen);
|
|
602 |
}
|
|
603 |
}
|
|
604 |
|
|
605 |
/*
|
|
606 |
* the following functions convert Attribute and Mechanism value pointers
|
|
607 |
*
|
|
608 |
* jobject ckAttributeValueToJObject(JNIEnv *env,
|
|
609 |
* const CK_ATTRIBUTE_PTR ckpAttribute);
|
|
610 |
*
|
|
611 |
* void jObjectToPrimitiveCKObjectPtrPtr(JNIEnv *env,
|
|
612 |
* jobject jObject,
|
|
613 |
* CK_VOID_PTR *ckpObjectPtr,
|
|
614 |
* CK_ULONG *pLength);
|
|
615 |
*
|
|
616 |
* void jMechanismParameterToCKMechanismParameter(JNIEnv *env,
|
|
617 |
* jobject jParam,
|
|
618 |
* CK_VOID_PTR *ckpParamPtr,
|
|
619 |
* CK_ULONG *ckpLength);
|
|
620 |
*
|
|
621 |
* These functions are used if a PKCS#11 mechanism or attribute structure gets
|
|
622 |
* convertet to a Java attribute or mechanism object or vice versa.
|
|
623 |
*
|
|
624 |
* ckAttributeValueToJObject converts a PKCS#11 attribute value pointer to a Java
|
|
625 |
* object depending on the type of the Attribute. A PKCS#11 attribute value can
|
|
626 |
* be a CK_ULONG, CK_BYTE[], CK_CHAR[], big integer, CK_BBOOL, CK_UTF8CHAR[],
|
|
627 |
* CK_DATE or CK_FLAGS that gets converted to a corresponding Java object.
|
|
628 |
*
|
|
629 |
* jObjectToPrimitiveCKObjectPtrPtr is used by jAttributeToCKAttributePtr for
|
|
630 |
* converting the Java attribute value to a PKCS#11 attribute value pointer.
|
|
631 |
* For now only primitive datatypes and arrays of primitive datatypes can get
|
|
632 |
* converted. Otherwise this function throws a PKCS#11Exception with the
|
|
633 |
* errorcode CKR_VENDOR_DEFINED.
|
|
634 |
*
|
|
635 |
* jMechanismParameterToCKMechanismParameter converts a Java mechanism parameter
|
|
636 |
* to a PKCS#11 mechanism parameter. First this function determines what mechanism
|
|
637 |
* parameter the Java object is, then it allocates the memory for the new PKCS#11
|
|
638 |
* structure and calls the corresponding function to convert the Java object to
|
|
639 |
* a PKCS#11 mechanism parameter structure.
|
|
640 |
*/
|
|
641 |
|
|
642 |
/*
|
|
643 |
* converts the pValue of a CK_ATTRIBUTE structure into a Java Object by checking the type
|
|
644 |
* of the attribute.
|
|
645 |
*
|
|
646 |
* @param env - used to call JNI funktions to create the new Java object
|
|
647 |
* @param ckpAttribute - the pointer to the CK_ATTRIBUTE structure that contains the type
|
|
648 |
* and the pValue to convert
|
|
649 |
* @return - the new Java object of the CK-type pValue
|
|
650 |
*/
|
|
651 |
jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute)
|
|
652 |
{
|
|
653 |
jint jValueLength;
|
|
654 |
jobject jValueObject = NULL;
|
|
655 |
|
|
656 |
jValueLength = ckULongToJInt(ckpAttribute->ulValueLen);
|
|
657 |
|
|
658 |
if ((jValueLength <= 0) || (ckpAttribute->pValue == NULL)) {
|
|
659 |
return NULL ;
|
|
660 |
}
|
|
661 |
|
|
662 |
switch(ckpAttribute->type) {
|
|
663 |
case CKA_CLASS:
|
|
664 |
/* value CK_OBJECT_CLASS, defacto a CK_ULONG */
|
|
665 |
case CKA_KEY_TYPE:
|
|
666 |
/* value CK_KEY_TYPE, defacto a CK_ULONG */
|
|
667 |
case CKA_CERTIFICATE_TYPE:
|
|
668 |
/* value CK_CERTIFICATE_TYPE, defacto a CK_ULONG */
|
|
669 |
case CKA_HW_FEATURE_TYPE:
|
|
670 |
/* value CK_HW_FEATURE_TYPE, defacto a CK_ULONG */
|
|
671 |
case CKA_MODULUS_BITS:
|
|
672 |
case CKA_VALUE_BITS:
|
|
673 |
case CKA_VALUE_LEN:
|
|
674 |
case CKA_KEY_GEN_MECHANISM:
|
|
675 |
case CKA_PRIME_BITS:
|
|
676 |
case CKA_SUB_PRIME_BITS:
|
|
677 |
/* value CK_ULONG */
|
|
678 |
jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
|
|
679 |
break;
|
|
680 |
|
|
681 |
/* can be CK_BYTE[],CK_CHAR[] or big integer; defacto always CK_BYTE[] */
|
|
682 |
case CKA_VALUE:
|
|
683 |
case CKA_OBJECT_ID:
|
|
684 |
case CKA_SUBJECT:
|
|
685 |
case CKA_ID:
|
|
686 |
case CKA_ISSUER:
|
|
687 |
case CKA_SERIAL_NUMBER:
|
|
688 |
case CKA_OWNER:
|
|
689 |
case CKA_AC_ISSUER:
|
|
690 |
case CKA_ATTR_TYPES:
|
|
691 |
case CKA_ECDSA_PARAMS:
|
|
692 |
/* CKA_EC_PARAMS is the same, these two are equivalent */
|
|
693 |
case CKA_EC_POINT:
|
|
694 |
case CKA_PRIVATE_EXPONENT:
|
|
695 |
case CKA_PRIME_1:
|
|
696 |
case CKA_PRIME_2:
|
|
697 |
case CKA_EXPONENT_1:
|
|
698 |
case CKA_EXPONENT_2:
|
|
699 |
case CKA_COEFFICIENT:
|
|
700 |
/* value CK_BYTE[] */
|
|
701 |
jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
|
|
702 |
break;
|
|
703 |
|
|
704 |
case CKA_RESET_ON_INIT:
|
|
705 |
case CKA_HAS_RESET:
|
|
706 |
case CKA_TOKEN:
|
|
707 |
case CKA_PRIVATE:
|
|
708 |
case CKA_MODIFIABLE:
|
|
709 |
case CKA_DERIVE:
|
|
710 |
case CKA_LOCAL:
|
|
711 |
case CKA_ENCRYPT:
|
|
712 |
case CKA_VERIFY:
|
|
713 |
case CKA_VERIFY_RECOVER:
|
|
714 |
case CKA_WRAP:
|
|
715 |
case CKA_SENSITIVE:
|
|
716 |
case CKA_SECONDARY_AUTH:
|
|
717 |
case CKA_DECRYPT:
|
|
718 |
case CKA_SIGN:
|
|
719 |
case CKA_SIGN_RECOVER:
|
|
720 |
case CKA_UNWRAP:
|
|
721 |
case CKA_EXTRACTABLE:
|
|
722 |
case CKA_ALWAYS_SENSITIVE:
|
|
723 |
case CKA_NEVER_EXTRACTABLE:
|
|
724 |
case CKA_TRUSTED:
|
|
725 |
/* value CK_BBOOL */
|
|
726 |
jValueObject = ckBBoolPtrToJBooleanObject(env, (CK_BBOOL*) ckpAttribute->pValue);
|
|
727 |
break;
|
|
728 |
|
|
729 |
case CKA_LABEL:
|
|
730 |
case CKA_APPLICATION:
|
|
731 |
/* value RFC 2279 (UTF-8) string */
|
|
732 |
jValueObject = ckUTF8CharArrayToJCharArray(env, (CK_UTF8CHAR*) ckpAttribute->pValue, jValueLength);
|
|
733 |
break;
|
|
734 |
|
|
735 |
case CKA_START_DATE:
|
|
736 |
case CKA_END_DATE:
|
|
737 |
/* value CK_DATE */
|
|
738 |
jValueObject = ckDatePtrToJDateObject(env, (CK_DATE*) ckpAttribute->pValue);
|
|
739 |
break;
|
|
740 |
|
|
741 |
case CKA_MODULUS:
|
|
742 |
case CKA_PUBLIC_EXPONENT:
|
|
743 |
case CKA_PRIME:
|
|
744 |
case CKA_SUBPRIME:
|
|
745 |
case CKA_BASE:
|
|
746 |
/* value big integer, i.e. CK_BYTE[] */
|
|
747 |
jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
|
|
748 |
break;
|
|
749 |
|
|
750 |
case CKA_AUTH_PIN_FLAGS:
|
|
751 |
jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
|
|
752 |
/* value FLAGS, defacto a CK_ULONG */
|
|
753 |
break;
|
|
754 |
|
|
755 |
case CKA_VENDOR_DEFINED:
|
|
756 |
/* we make a CK_BYTE[] out of this */
|
|
757 |
jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
|
|
758 |
break;
|
|
759 |
|
|
760 |
// Netscape trust attributes
|
|
761 |
case CKA_NETSCAPE_TRUST_SERVER_AUTH:
|
|
762 |
case CKA_NETSCAPE_TRUST_CLIENT_AUTH:
|
|
763 |
case CKA_NETSCAPE_TRUST_CODE_SIGNING:
|
|
764 |
case CKA_NETSCAPE_TRUST_EMAIL_PROTECTION:
|
|
765 |
/* value CK_ULONG */
|
|
766 |
jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
|
|
767 |
break;
|
|
768 |
|
|
769 |
default:
|
|
770 |
/* we make a CK_BYTE[] out of this */
|
|
771 |
jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
|
|
772 |
break;
|
|
773 |
}
|
|
774 |
|
|
775 |
return jValueObject ;
|
|
776 |
}
|
|
777 |
|
|
778 |
/*
|
|
779 |
* the following functions convert a Java mechanism parameter object to a PKCS#11
|
|
780 |
* mechanism parameter structure
|
|
781 |
*
|
|
782 |
* CK_<Param>_PARAMS j<Param>ParamToCK<Param>Param(JNIEnv *env,
|
|
783 |
* jobject jParam);
|
|
784 |
*
|
|
785 |
* These functions get a Java object, that must be the right Java mechanism
|
|
786 |
* object and they return the new PKCS#11 mechanism parameter structure.
|
|
787 |
* Every field of the Java object is retrieved, gets converted to a corresponding
|
|
788 |
* PKCS#11 type and is set in the new PKCS#11 structure.
|
|
789 |
*/
|
|
790 |
|
|
791 |
/*
|
|
792 |
* converts the given Java mechanism parameter to a CK mechanism parameter structure
|
|
793 |
* and store the length in bytes in the length variable.
|
|
794 |
* The memory of *ckpParamPtr has to be freed after use!
|
|
795 |
*
|
|
796 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
797 |
* @param jParam - the Java mechanism parameter object to convert
|
|
798 |
* @param ckpParamPtr - the reference of the new pointer to the new CK mechanism parameter
|
|
799 |
* structure
|
|
800 |
* @param ckpLength - the reference of the length in bytes of the new CK mechanism parameter
|
|
801 |
* structure
|
|
802 |
*/
|
|
803 |
void jMechanismParameterToCKMechanismParameter(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength)
|
|
804 |
{
|
|
805 |
if (jParam == NULL) {
|
|
806 |
*ckpParamPtr = NULL;
|
|
807 |
*ckpLength = 0;
|
|
808 |
} else if ((*env)->IsInstanceOf(env, jParam, jByteArrayClass)) {
|
|
809 |
jByteArrayToCKByteArray(env, jParam, (CK_BYTE_PTR *)ckpParamPtr, ckpLength);
|
|
810 |
} else if ((*env)->IsInstanceOf(env, jParam, jLongClass)) {
|
|
811 |
*ckpParamPtr = jLongObjectToCKULongPtr(env, jParam);
|
|
812 |
*ckpLength = sizeof(CK_ULONG);
|
|
813 |
} else {
|
|
814 |
/* printf("slow path jMechanismParameterToCKMechanismParameter\n"); */
|
|
815 |
jMechanismParameterToCKMechanismParameterSlow(env, jParam, ckpParamPtr, ckpLength);
|
|
816 |
}
|
|
817 |
}
|
|
818 |
|
|
819 |
void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam, CK_VOID_PTR *ckpParamPtr, CK_ULONG *ckpLength)
|
|
820 |
{
|
|
821 |
/* get all Java mechanism parameter classes */
|
|
822 |
jclass jVersionClass = (*env)->FindClass(env, CLASS_VERSION);
|
|
823 |
jclass jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS);
|
|
824 |
jclass jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS);
|
|
825 |
jclass jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS);
|
|
826 |
|
|
827 |
jclass jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS);
|
|
828 |
jclass jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS);
|
|
829 |
jclass jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS);
|
|
830 |
jclass jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS);
|
|
831 |
jclass jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS);
|
|
832 |
|
|
833 |
jclass jSsl3MasterKeyDeriveParamsClass = (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS);
|
|
834 |
jclass jSsl3KeyMatParamsClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_PARAMS);
|
|
835 |
jclass jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS);
|
|
836 |
|
|
837 |
TRACE0("\nDEBUG: jMechanismParameterToCKMechanismParameter");
|
|
838 |
|
|
839 |
/* first check the most common cases */
|
|
840 |
/*
|
|
841 |
if (jParam == NULL) {
|
|
842 |
*ckpParamPtr = NULL;
|
|
843 |
*ckpLength = 0;
|
|
844 |
} else if ((*env)->IsInstanceOf(env, jParam, jByteArrayClass)) {
|
|
845 |
jByteArrayToCKByteArray(env, jParam, (CK_BYTE_PTR *)ckpParamPtr, ckpLength);
|
|
846 |
} else if ((*env)->IsInstanceOf(env, jParam, jLongClass)) {
|
|
847 |
*ckpParamPtr = jLongObjectToCKULongPtr(env, jParam);
|
|
848 |
*ckpLength = sizeof(CK_ULONG);
|
|
849 |
} else if ((*env)->IsInstanceOf(env, jParam, jVersionClass)) {
|
|
850 |
*/
|
|
851 |
if ((*env)->IsInstanceOf(env, jParam, jVersionClass)) {
|
|
852 |
/*
|
|
853 |
* CK_VERSION used by CKM_SSL3_PRE_MASTER_KEY_GEN
|
|
854 |
*/
|
|
855 |
|
|
856 |
CK_VERSION_PTR ckpParam;
|
|
857 |
|
|
858 |
/* convert jParameter to CKParameter */
|
|
859 |
ckpParam = jVersionToCKVersionPtr(env, jParam);
|
|
860 |
|
|
861 |
/* get length and pointer of parameter */
|
|
862 |
*ckpLength = sizeof(CK_VERSION);
|
|
863 |
*ckpParamPtr = ckpParam;
|
|
864 |
|
|
865 |
} else if ((*env)->IsInstanceOf(env, jParam, jSsl3MasterKeyDeriveParamsClass)) {
|
|
866 |
/*
|
|
867 |
* CK_SSL3_MASTER_KEY_DERIVE_PARAMS
|
|
868 |
*/
|
|
869 |
|
|
870 |
CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR ckpParam;
|
|
871 |
|
|
872 |
ckpParam = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR) malloc(sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS));
|
|
873 |
|
|
874 |
/* convert jParameter to CKParameter */
|
|
875 |
*ckpParam = jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParam(env, jParam);
|
|
876 |
|
|
877 |
/* get length and pointer of parameter */
|
|
878 |
*ckpLength = sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS);
|
|
879 |
*ckpParamPtr = ckpParam;
|
|
880 |
|
|
881 |
} else if ((*env)->IsInstanceOf(env, jParam, jSsl3KeyMatParamsClass)) {
|
|
882 |
/*
|
|
883 |
* CK_SSL3_KEY_MAT_PARAMS
|
|
884 |
*/
|
|
885 |
|
|
886 |
CK_SSL3_KEY_MAT_PARAMS_PTR ckpParam;
|
|
887 |
|
|
888 |
ckpParam = (CK_SSL3_KEY_MAT_PARAMS_PTR) malloc(sizeof(CK_SSL3_KEY_MAT_PARAMS));
|
|
889 |
|
|
890 |
/* convert jParameter to CKParameter */
|
|
891 |
*ckpParam = jSsl3KeyMatParamToCKSsl3KeyMatParam(env, jParam);
|
|
892 |
|
|
893 |
/* get length and pointer of parameter */
|
|
894 |
*ckpLength = sizeof(CK_SSL3_KEY_MAT_PARAMS);
|
|
895 |
*ckpParamPtr = ckpParam;
|
|
896 |
|
|
897 |
} else if ((*env)->IsInstanceOf(env, jParam, jTlsPrfParamsClass)) {
|
|
898 |
//
|
|
899 |
// CK_TLS_PRF_PARAMS
|
|
900 |
//
|
|
901 |
|
|
902 |
CK_TLS_PRF_PARAMS_PTR ckpParam;
|
|
903 |
|
|
904 |
ckpParam = (CK_TLS_PRF_PARAMS_PTR) malloc(sizeof(CK_TLS_PRF_PARAMS));
|
|
905 |
|
|
906 |
// convert jParameter to CKParameter
|
|
907 |
*ckpParam = jTlsPrfParamsToCKTlsPrfParam(env, jParam);
|
|
908 |
|
|
909 |
// get length and pointer of parameter
|
|
910 |
*ckpLength = sizeof(CK_TLS_PRF_PARAMS);
|
|
911 |
*ckpParamPtr = ckpParam;
|
|
912 |
|
|
913 |
} else if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsOaepParamsClass)) {
|
|
914 |
/*
|
|
915 |
* CK_RSA_PKCS_OAEP_PARAMS
|
|
916 |
*/
|
|
917 |
|
|
918 |
CK_RSA_PKCS_OAEP_PARAMS_PTR ckpParam;
|
|
919 |
|
|
920 |
ckpParam = (CK_RSA_PKCS_OAEP_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_OAEP_PARAMS));
|
|
921 |
|
|
922 |
/* convert jParameter to CKParameter */
|
|
923 |
*ckpParam = jRsaPkcsOaepParamToCKRsaPkcsOaepParam(env, jParam);
|
|
924 |
|
|
925 |
/* get length and pointer of parameter */
|
|
926 |
*ckpLength = sizeof(CK_RSA_PKCS_OAEP_PARAMS);
|
|
927 |
*ckpParamPtr = ckpParam;
|
|
928 |
|
|
929 |
} else if ((*env)->IsInstanceOf(env, jParam, jPbeParamsClass)) {
|
|
930 |
/*
|
|
931 |
* CK_PBE_PARAMS
|
|
932 |
*/
|
|
933 |
|
|
934 |
CK_PBE_PARAMS_PTR ckpParam;
|
|
935 |
|
|
936 |
ckpParam = (CK_PBE_PARAMS_PTR) malloc(sizeof(CK_PBE_PARAMS));
|
|
937 |
|
|
938 |
/* convert jParameter to CKParameter */
|
|
939 |
*ckpParam = jPbeParamToCKPbeParam(env, jParam);
|
|
940 |
|
|
941 |
/* get length and pointer of parameter */
|
|
942 |
*ckpLength = sizeof(CK_PBE_PARAMS);
|
|
943 |
*ckpParamPtr = ckpParam;
|
|
944 |
|
|
945 |
} else if ((*env)->IsInstanceOf(env, jParam, jPkcs5Pbkd2ParamsClass)) {
|
|
946 |
/*
|
|
947 |
* CK_PKCS5_PBKD2_PARAMS
|
|
948 |
*/
|
|
949 |
|
|
950 |
CK_PKCS5_PBKD2_PARAMS_PTR ckpParam;
|
|
951 |
|
|
952 |
ckpParam = (CK_PKCS5_PBKD2_PARAMS_PTR) malloc(sizeof(CK_PKCS5_PBKD2_PARAMS));
|
|
953 |
|
|
954 |
/* convert jParameter to CKParameter */
|
|
955 |
*ckpParam = jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(env, jParam);
|
|
956 |
|
|
957 |
/* get length and pointer of parameter */
|
|
958 |
*ckpLength = sizeof(CK_PKCS5_PBKD2_PARAMS);
|
|
959 |
*ckpParamPtr = ckpParam;
|
|
960 |
|
|
961 |
} else if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsPssParamsClass)) {
|
|
962 |
/*
|
|
963 |
* CK_RSA_PKCS_PSS_PARAMS
|
|
964 |
*/
|
|
965 |
|
|
966 |
CK_RSA_PKCS_PSS_PARAMS_PTR ckpParam;
|
|
967 |
|
|
968 |
ckpParam = (CK_RSA_PKCS_PSS_PARAMS_PTR) malloc(sizeof(CK_RSA_PKCS_PSS_PARAMS));
|
|
969 |
|
|
970 |
/* convert jParameter to CKParameter */
|
|
971 |
*ckpParam = jRsaPkcsPssParamToCKRsaPkcsPssParam(env, jParam);
|
|
972 |
|
|
973 |
/* get length and pointer of parameter */
|
|
974 |
*ckpLength = sizeof(CK_RSA_PKCS_PSS_PARAMS);
|
|
975 |
*ckpParamPtr = ckpParam;
|
|
976 |
|
|
977 |
} else if ((*env)->IsInstanceOf(env, jParam, jEcdh1DeriveParamsClass)) {
|
|
978 |
/*
|
|
979 |
* CK_ECDH1_DERIVE_PARAMS
|
|
980 |
*/
|
|
981 |
|
|
982 |
CK_ECDH1_DERIVE_PARAMS_PTR ckpParam;
|
|
983 |
|
|
984 |
ckpParam = (CK_ECDH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH1_DERIVE_PARAMS));
|
|
985 |
|
|
986 |
/* convert jParameter to CKParameter */
|
|
987 |
*ckpParam = jEcdh1DeriveParamToCKEcdh1DeriveParam(env, jParam);
|
|
988 |
|
|
989 |
/* get length and pointer of parameter */
|
|
990 |
*ckpLength = sizeof(CK_ECDH1_DERIVE_PARAMS);
|
|
991 |
*ckpParamPtr = ckpParam;
|
|
992 |
|
|
993 |
} else if ((*env)->IsInstanceOf(env, jParam, jEcdh2DeriveParamsClass)) {
|
|
994 |
/*
|
|
995 |
* CK_ECDH2_DERIVE_PARAMS
|
|
996 |
*/
|
|
997 |
|
|
998 |
CK_ECDH2_DERIVE_PARAMS_PTR ckpParam;
|
|
999 |
|
|
1000 |
ckpParam = (CK_ECDH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_ECDH2_DERIVE_PARAMS));
|
|
1001 |
|
|
1002 |
/* convert jParameter to CKParameter */
|
|
1003 |
*ckpParam = jEcdh2DeriveParamToCKEcdh2DeriveParam(env, jParam);
|
|
1004 |
|
|
1005 |
/* get length and pointer of parameter */
|
|
1006 |
*ckpLength = sizeof(CK_ECDH2_DERIVE_PARAMS);
|
|
1007 |
*ckpParamPtr = ckpParam;
|
|
1008 |
|
|
1009 |
} else if ((*env)->IsInstanceOf(env, jParam, jX942Dh1DeriveParamsClass)) {
|
|
1010 |
/*
|
|
1011 |
* CK_X9_42_DH1_DERIVE_PARAMS
|
|
1012 |
*/
|
|
1013 |
|
|
1014 |
CK_X9_42_DH1_DERIVE_PARAMS_PTR ckpParam;
|
|
1015 |
|
|
1016 |
ckpParam = (CK_X9_42_DH1_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH1_DERIVE_PARAMS));
|
|
1017 |
|
|
1018 |
/* convert jParameter to CKParameter */
|
|
1019 |
*ckpParam = jX942Dh1DeriveParamToCKX942Dh1DeriveParam(env, jParam);
|
|
1020 |
|
|
1021 |
/* get length and pointer of parameter */
|
|
1022 |
*ckpLength = sizeof(CK_X9_42_DH1_DERIVE_PARAMS);
|
|
1023 |
*ckpParamPtr = ckpParam;
|
|
1024 |
|
|
1025 |
} else if ((*env)->IsInstanceOf(env, jParam, jX942Dh2DeriveParamsClass)) {
|
|
1026 |
/*
|
|
1027 |
* CK_X9_42_DH2_DERIVE_PARAMS
|
|
1028 |
*/
|
|
1029 |
|
|
1030 |
CK_X9_42_DH2_DERIVE_PARAMS_PTR ckpParam;
|
|
1031 |
|
|
1032 |
ckpParam = (CK_X9_42_DH2_DERIVE_PARAMS_PTR) malloc(sizeof(CK_X9_42_DH2_DERIVE_PARAMS));
|
|
1033 |
|
|
1034 |
/* convert jParameter to CKParameter */
|
|
1035 |
*ckpParam = jX942Dh2DeriveParamToCKX942Dh2DeriveParam(env, jParam);
|
|
1036 |
|
|
1037 |
/* get length and pointer of parameter */
|
|
1038 |
*ckpLength = sizeof(CK_X9_42_DH2_DERIVE_PARAMS);
|
|
1039 |
*ckpParamPtr = ckpParam;
|
|
1040 |
|
|
1041 |
} else {
|
|
1042 |
/* if everything faild up to here */
|
|
1043 |
/* try if the parameter is a primitive Java type */
|
|
1044 |
jObjectToPrimitiveCKObjectPtrPtr(env, jParam, ckpParamPtr, ckpLength);
|
|
1045 |
/* *ckpParamPtr = jObjectToCKVoidPtr(jParam); */
|
|
1046 |
/* *ckpLength = 1; */
|
|
1047 |
}
|
|
1048 |
|
|
1049 |
TRACE0("FINISHED\n");
|
|
1050 |
}
|
|
1051 |
|
|
1052 |
|
|
1053 |
/* the mechanism parameter convertion functions: */
|
|
1054 |
|
|
1055 |
/*
|
|
1056 |
* converts the Java CK_RSA_PKCS_OAEP_PARAMS object to a CK_RSA_PKCS_OAEP_PARAMS structure
|
|
1057 |
*
|
|
1058 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
1059 |
* @param jParam - the Java CK_RSA_PKCS_OAEP_PARAMS object to convert
|
|
1060 |
* @return - the new CK_RSA_PKCS_OAEP_PARAMS structure
|
|
1061 |
*/
|
|
1062 |
CK_RSA_PKCS_OAEP_PARAMS jRsaPkcsOaepParamToCKRsaPkcsOaepParam(JNIEnv *env, jobject jParam)
|
|
1063 |
{
|
|
1064 |
jclass jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS);
|
|
1065 |
CK_RSA_PKCS_OAEP_PARAMS ckParam;
|
|
1066 |
jfieldID fieldID;
|
|
1067 |
jlong jLong;
|
|
1068 |
jobject jObject;
|
|
1069 |
CK_BYTE_PTR ckpByte;
|
|
1070 |
|
|
1071 |
/* get hashAlg */
|
|
1072 |
fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "hashAlg", "J");
|
|
1073 |
assert(fieldID != 0);
|
|
1074 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1075 |
ckParam.hashAlg = jLongToCKULong(jLong);
|
|
1076 |
|
|
1077 |
/* get mgf */
|
|
1078 |
fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "mgf", "J");
|
|
1079 |
assert(fieldID != 0);
|
|
1080 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1081 |
ckParam.mgf = jLongToCKULong(jLong);
|
|
1082 |
|
|
1083 |
/* get source */
|
|
1084 |
fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "source", "J");
|
|
1085 |
assert(fieldID != 0);
|
|
1086 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1087 |
ckParam.source = jLongToCKULong(jLong);
|
|
1088 |
|
|
1089 |
/* get sourceData and sourceDataLength */
|
|
1090 |
fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "pSourceData", "[B");
|
|
1091 |
assert(fieldID != 0);
|
|
1092 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1093 |
jByteArrayToCKByteArray(env, jObject, &ckpByte, &(ckParam.ulSourceDataLen));
|
|
1094 |
ckParam.pSourceData = (CK_VOID_PTR) ckpByte;
|
|
1095 |
|
|
1096 |
return ckParam ;
|
|
1097 |
}
|
|
1098 |
|
|
1099 |
/*
|
|
1100 |
* converts the Java CK_PBE_PARAMS object to a CK_PBE_PARAMS structure
|
|
1101 |
*
|
|
1102 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
1103 |
* @param jParam - the Java CK_PBE_PARAMS object to convert
|
|
1104 |
* @return - the new CK_PBE_PARAMS structure
|
|
1105 |
*/
|
|
1106 |
CK_PBE_PARAMS jPbeParamToCKPbeParam(JNIEnv *env, jobject jParam)
|
|
1107 |
{
|
|
1108 |
jclass jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS);
|
|
1109 |
CK_PBE_PARAMS ckParam;
|
|
1110 |
jfieldID fieldID;
|
|
1111 |
jlong jLong;
|
|
1112 |
jobject jObject;
|
|
1113 |
CK_ULONG ckTemp;
|
|
1114 |
|
|
1115 |
/* get pInitVector */
|
|
1116 |
fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVector", "[C");
|
|
1117 |
assert(fieldID != 0);
|
|
1118 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1119 |
jCharArrayToCKCharArray(env, jObject, &(ckParam.pInitVector), &ckTemp);
|
|
1120 |
|
|
1121 |
/* get pPassword and ulPasswordLength */
|
|
1122 |
fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pPassword", "[C");
|
|
1123 |
assert(fieldID != 0);
|
|
1124 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1125 |
jCharArrayToCKCharArray(env, jObject, &(ckParam.pPassword), &(ckParam.ulPasswordLen));
|
|
1126 |
|
|
1127 |
/* get pSalt and ulSaltLength */
|
|
1128 |
fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pSalt", "[C");
|
|
1129 |
assert(fieldID != 0);
|
|
1130 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1131 |
jCharArrayToCKCharArray(env, jObject, &(ckParam.pSalt), &(ckParam.ulSaltLen));
|
|
1132 |
|
|
1133 |
/* get ulIteration */
|
|
1134 |
fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "ulIteration", "J");
|
|
1135 |
assert(fieldID != 0);
|
|
1136 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1137 |
ckParam.ulIteration = jLongToCKULong(jLong);
|
|
1138 |
|
|
1139 |
return ckParam ;
|
|
1140 |
}
|
|
1141 |
|
|
1142 |
/*
|
|
1143 |
* Copy back the initialization vector from the native structure to the
|
|
1144 |
* Java object. This is only used for CKM_PBE_* mechanisms and their
|
|
1145 |
* CK_PBE_PARAMS parameters.
|
|
1146 |
*
|
|
1147 |
*/
|
|
1148 |
void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism)
|
|
1149 |
{
|
|
1150 |
jclass jMechanismClass= (*env)->FindClass(env, CLASS_MECHANISM);
|
|
1151 |
jclass jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS);
|
|
1152 |
CK_PBE_PARAMS *ckParam;
|
|
1153 |
jfieldID fieldID;
|
|
1154 |
CK_MECHANISM_TYPE ckMechanismType;
|
|
1155 |
jlong jMechanismType;
|
|
1156 |
jobject jParameter;
|
|
1157 |
jobject jInitVector;
|
|
1158 |
jint jInitVectorLength;
|
|
1159 |
CK_CHAR_PTR initVector;
|
|
1160 |
int i;
|
|
1161 |
jchar* jInitVectorChars;
|
|
1162 |
|
|
1163 |
/* get mechanism */
|
|
1164 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J");
|
|
1165 |
assert(fieldID != 0);
|
|
1166 |
jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID);
|
|
1167 |
ckMechanismType = jLongToCKULong(jMechanismType);
|
|
1168 |
if (ckMechanismType != ckMechanism->mechanism) {
|
|
1169 |
/* we do not have maching types, this should not occur */
|
|
1170 |
return;
|
|
1171 |
}
|
|
1172 |
|
|
1173 |
ckParam = (CK_PBE_PARAMS *) ckMechanism->pParameter;
|
|
1174 |
if (ckParam != NULL_PTR) {
|
|
1175 |
initVector = ckParam->pInitVector;
|
|
1176 |
if (initVector != NULL_PTR) {
|
|
1177 |
/* get pParameter */
|
|
1178 |
fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;");
|
|
1179 |
assert(fieldID != 0);
|
|
1180 |
jParameter = (*env)->GetObjectField(env, jMechanism, fieldID);
|
|
1181 |
fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVektor", "[C");
|
|
1182 |
assert(fieldID != 0);
|
|
1183 |
jInitVector = (*env)->GetObjectField(env, jParameter, fieldID);
|
|
1184 |
|
|
1185 |
if (jInitVector != NULL) {
|
|
1186 |
jInitVectorLength = (*env)->GetArrayLength(env, jInitVector);
|
|
1187 |
jInitVectorChars = (*env)->GetCharArrayElements(env, jInitVector, NULL);
|
|
1188 |
/* copy the chars to the Java buffer */
|
|
1189 |
for (i=0; i < jInitVectorLength; i++) {
|
|
1190 |
jInitVectorChars[i] = ckCharToJChar(initVector[i]);
|
|
1191 |
}
|
|
1192 |
/* copy back the Java buffer to the object */
|
|
1193 |
(*env)->ReleaseCharArrayElements(env, jInitVector, jInitVectorChars, 0);
|
|
1194 |
}
|
|
1195 |
}
|
|
1196 |
}
|
|
1197 |
}
|
|
1198 |
|
|
1199 |
/*
|
|
1200 |
* converts the Java CK_PKCS5_PBKD2_PARAMS object to a CK_PKCS5_PBKD2_PARAMS structure
|
|
1201 |
*
|
|
1202 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
1203 |
* @param jParam - the Java CK_PKCS5_PBKD2_PARAMS object to convert
|
|
1204 |
* @return - the new CK_PKCS5_PBKD2_PARAMS structure
|
|
1205 |
*/
|
|
1206 |
CK_PKCS5_PBKD2_PARAMS jPkcs5Pbkd2ParamToCKPkcs5Pbkd2Param(JNIEnv *env, jobject jParam)
|
|
1207 |
{
|
|
1208 |
jclass jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS);
|
|
1209 |
CK_PKCS5_PBKD2_PARAMS ckParam;
|
|
1210 |
jfieldID fieldID;
|
|
1211 |
jlong jLong;
|
|
1212 |
jobject jObject;
|
|
1213 |
|
|
1214 |
/* get saltSource */
|
|
1215 |
fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "saltSource", "J");
|
|
1216 |
assert(fieldID != 0);
|
|
1217 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1218 |
ckParam.saltSource = jLongToCKULong(jLong);
|
|
1219 |
|
|
1220 |
/* get pSaltSourceData */
|
|
1221 |
fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pSaltSourceData", "[B");
|
|
1222 |
assert(fieldID != 0);
|
|
1223 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1224 |
jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR *) &(ckParam.pSaltSourceData), &(ckParam.ulSaltSourceDataLen));
|
|
1225 |
|
|
1226 |
/* get iterations */
|
|
1227 |
fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "iterations", "J");
|
|
1228 |
assert(fieldID != 0);
|
|
1229 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1230 |
ckParam.iterations = jLongToCKULong(jLong);
|
|
1231 |
|
|
1232 |
/* get prf */
|
|
1233 |
fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "prf", "J");
|
|
1234 |
assert(fieldID != 0);
|
|
1235 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1236 |
ckParam.prf = jLongToCKULong(jLong);
|
|
1237 |
|
|
1238 |
/* get pPrfData and ulPrfDataLength in byte */
|
|
1239 |
fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pPrfData", "[B");
|
|
1240 |
assert(fieldID != 0);
|
|
1241 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1242 |
jByteArrayToCKByteArray(env, jObject, (CK_BYTE_PTR *) &(ckParam.pPrfData), &(ckParam.ulPrfDataLen));
|
|
1243 |
|
|
1244 |
return ckParam ;
|
|
1245 |
}
|
|
1246 |
|
|
1247 |
/*
|
|
1248 |
* converts the Java CK_RSA_PKCS_PSS_PARAMS object to a CK_RSA_PKCS_PSS_PARAMS structure
|
|
1249 |
*
|
|
1250 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
1251 |
* @param jParam - the Java CK_RSA_PKCS_PSS_PARAMS object to convert
|
|
1252 |
* @return - the new CK_RSA_PKCS_PSS_PARAMS structure
|
|
1253 |
*/
|
|
1254 |
CK_RSA_PKCS_PSS_PARAMS jRsaPkcsPssParamToCKRsaPkcsPssParam(JNIEnv *env, jobject jParam)
|
|
1255 |
{
|
|
1256 |
jclass jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS);
|
|
1257 |
CK_RSA_PKCS_PSS_PARAMS ckParam;
|
|
1258 |
jfieldID fieldID;
|
|
1259 |
jlong jLong;
|
|
1260 |
|
|
1261 |
/* get hashAlg */
|
|
1262 |
fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "hashAlg", "J");
|
|
1263 |
assert(fieldID != 0);
|
|
1264 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1265 |
ckParam.hashAlg = jLongToCKULong(jLong);
|
|
1266 |
|
|
1267 |
/* get mgf */
|
|
1268 |
fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "mgf", "J");
|
|
1269 |
assert(fieldID != 0);
|
|
1270 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1271 |
ckParam.mgf = jLongToCKULong(jLong);
|
|
1272 |
|
|
1273 |
/* get sLen */
|
|
1274 |
fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "sLen", "J");
|
|
1275 |
assert(fieldID != 0);
|
|
1276 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1277 |
ckParam.sLen = jLongToCKULong(jLong);
|
|
1278 |
|
|
1279 |
return ckParam ;
|
|
1280 |
}
|
|
1281 |
|
|
1282 |
/*
|
|
1283 |
* converts the Java CK_ECDH1_DERIVE_PARAMS object to a CK_ECDH1_DERIVE_PARAMS structure
|
|
1284 |
*
|
|
1285 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
1286 |
* @param jParam - the Java CK_ECDH1_DERIVE_PARAMS object to convert
|
|
1287 |
* @return - the new CK_ECDH1_DERIVE_PARAMS structure
|
|
1288 |
*/
|
|
1289 |
CK_ECDH1_DERIVE_PARAMS jEcdh1DeriveParamToCKEcdh1DeriveParam(JNIEnv *env, jobject jParam)
|
|
1290 |
{
|
|
1291 |
jclass jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS);
|
|
1292 |
CK_ECDH1_DERIVE_PARAMS ckParam;
|
|
1293 |
jfieldID fieldID;
|
|
1294 |
jlong jLong;
|
|
1295 |
jobject jObject;
|
|
1296 |
|
|
1297 |
/* get kdf */
|
|
1298 |
fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "kdf", "J");
|
|
1299 |
assert(fieldID != 0);
|
|
1300 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1301 |
ckParam.kdf = jLongToCKULong(jLong);
|
|
1302 |
|
|
1303 |
/* get pSharedData and ulSharedDataLen */
|
|
1304 |
fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pSharedData", "[B");
|
|
1305 |
assert(fieldID != 0);
|
|
1306 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1307 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen));
|
|
1308 |
|
|
1309 |
/* get pPublicData and ulPublicDataLen */
|
|
1310 |
fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pPublicData", "[B");
|
|
1311 |
assert(fieldID != 0);
|
|
1312 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1313 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
|
|
1314 |
|
|
1315 |
return ckParam ;
|
|
1316 |
}
|
|
1317 |
|
|
1318 |
/*
|
|
1319 |
* converts the Java CK_ECDH2_DERIVE_PARAMS object to a CK_ECDH2_DERIVE_PARAMS structure
|
|
1320 |
*
|
|
1321 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
1322 |
* @param jParam - the Java CK_ECDH2_DERIVE_PARAMS object to convert
|
|
1323 |
* @return - the new CK_ECDH2_DERIVE_PARAMS structure
|
|
1324 |
*/
|
|
1325 |
CK_ECDH2_DERIVE_PARAMS jEcdh2DeriveParamToCKEcdh2DeriveParam(JNIEnv *env, jobject jParam)
|
|
1326 |
{
|
|
1327 |
jclass jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS);
|
|
1328 |
CK_ECDH2_DERIVE_PARAMS ckParam;
|
|
1329 |
jfieldID fieldID;
|
|
1330 |
jlong jLong;
|
|
1331 |
jobject jObject;
|
|
1332 |
|
|
1333 |
/* get kdf */
|
|
1334 |
fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "kdf", "J");
|
|
1335 |
assert(fieldID != 0);
|
|
1336 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1337 |
ckParam.kdf = jLongToCKULong(jLong);
|
|
1338 |
|
|
1339 |
/* get pSharedData and ulSharedDataLen */
|
|
1340 |
fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pSharedData", "[B");
|
|
1341 |
assert(fieldID != 0);
|
|
1342 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1343 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pSharedData), &(ckParam.ulSharedDataLen));
|
|
1344 |
|
|
1345 |
/* get pPublicData and ulPublicDataLen */
|
|
1346 |
fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData", "[B");
|
|
1347 |
assert(fieldID != 0);
|
|
1348 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1349 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
|
|
1350 |
|
|
1351 |
/* get ulPrivateDataLen */
|
|
1352 |
fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "ulPrivateDataLen", "J");
|
|
1353 |
assert(fieldID != 0);
|
|
1354 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1355 |
ckParam.ulPrivateDataLen = jLongToCKULong(jLong);
|
|
1356 |
|
|
1357 |
/* get hPrivateData */
|
|
1358 |
fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "hPrivateData", "J");
|
|
1359 |
assert(fieldID != 0);
|
|
1360 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1361 |
ckParam.hPrivateData = jLongToCKULong(jLong);
|
|
1362 |
|
|
1363 |
/* get pPublicData2 and ulPublicDataLen2 */
|
|
1364 |
fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData2", "[B");
|
|
1365 |
assert(fieldID != 0);
|
|
1366 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1367 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2));
|
|
1368 |
|
|
1369 |
return ckParam ;
|
|
1370 |
}
|
|
1371 |
|
|
1372 |
/*
|
|
1373 |
* converts the Java CK_X9_42_DH1_DERIVE_PARAMS object to a CK_X9_42_DH1_DERIVE_PARAMS structure
|
|
1374 |
*
|
|
1375 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
1376 |
* @param jParam - the Java CK_X9_42_DH1_DERIVE_PARAMS object to convert
|
|
1377 |
* @return - the new CK_X9_42_DH1_DERIVE_PARAMS structure
|
|
1378 |
*/
|
|
1379 |
CK_X9_42_DH1_DERIVE_PARAMS jX942Dh1DeriveParamToCKX942Dh1DeriveParam(JNIEnv *env, jobject jParam)
|
|
1380 |
{
|
|
1381 |
jclass jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS);
|
|
1382 |
CK_X9_42_DH1_DERIVE_PARAMS ckParam;
|
|
1383 |
jfieldID fieldID;
|
|
1384 |
jlong jLong;
|
|
1385 |
jobject jObject;
|
|
1386 |
|
|
1387 |
/* get kdf */
|
|
1388 |
fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "kdf", "J");
|
|
1389 |
assert(fieldID != 0);
|
|
1390 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1391 |
ckParam.kdf = jLongToCKULong(jLong);
|
|
1392 |
|
|
1393 |
/* get pOtherInfo and ulOtherInfoLen */
|
|
1394 |
fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pOtherInfo", "[B");
|
|
1395 |
assert(fieldID != 0);
|
|
1396 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1397 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen));
|
|
1398 |
|
|
1399 |
/* get pPublicData and ulPublicDataLen */
|
|
1400 |
fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pPublicData", "[B");
|
|
1401 |
assert(fieldID != 0);
|
|
1402 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1403 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
|
|
1404 |
|
|
1405 |
return ckParam ;
|
|
1406 |
}
|
|
1407 |
|
|
1408 |
/*
|
|
1409 |
* converts the Java CK_X9_42_DH2_DERIVE_PARAMS object to a CK_X9_42_DH2_DERIVE_PARAMS structure
|
|
1410 |
*
|
|
1411 |
* @param env - used to call JNI funktions to get the Java classes and objects
|
|
1412 |
* @param jParam - the Java CK_X9_42_DH2_DERIVE_PARAMS object to convert
|
|
1413 |
* @return - the new CK_X9_42_DH2_DERIVE_PARAMS structure
|
|
1414 |
*/
|
|
1415 |
CK_X9_42_DH2_DERIVE_PARAMS jX942Dh2DeriveParamToCKX942Dh2DeriveParam(JNIEnv *env, jobject jParam)
|
|
1416 |
{
|
|
1417 |
jclass jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS);
|
|
1418 |
CK_X9_42_DH2_DERIVE_PARAMS ckParam;
|
|
1419 |
jfieldID fieldID;
|
|
1420 |
jlong jLong;
|
|
1421 |
jobject jObject;
|
|
1422 |
|
|
1423 |
/* get kdf */
|
|
1424 |
fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "kdf", "J");
|
|
1425 |
assert(fieldID != 0);
|
|
1426 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1427 |
ckParam.kdf = jLongToCKULong(jLong);
|
|
1428 |
|
|
1429 |
/* get pOtherInfo and ulOtherInfoLen */
|
|
1430 |
fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pOtherInfo", "[B");
|
|
1431 |
assert(fieldID != 0);
|
|
1432 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1433 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pOtherInfo), &(ckParam.ulOtherInfoLen));
|
|
1434 |
|
|
1435 |
/* get pPublicData and ulPublicDataLen */
|
|
1436 |
fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData", "[B");
|
|
1437 |
assert(fieldID != 0);
|
|
1438 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1439 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData), &(ckParam.ulPublicDataLen));
|
|
1440 |
|
|
1441 |
/* get ulPrivateDataLen */
|
|
1442 |
fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "ulPrivateDataLen", "J");
|
|
1443 |
assert(fieldID != 0);
|
|
1444 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1445 |
ckParam.ulPrivateDataLen = jLongToCKULong(jLong);
|
|
1446 |
|
|
1447 |
/* get hPrivateData */
|
|
1448 |
fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "hPrivateData", "J");
|
|
1449 |
assert(fieldID != 0);
|
|
1450 |
jLong = (*env)->GetLongField(env, jParam, fieldID);
|
|
1451 |
ckParam.hPrivateData = jLongToCKULong(jLong);
|
|
1452 |
|
|
1453 |
/* get pPublicData2 and ulPublicDataLen2 */
|
|
1454 |
fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData2", "[B");
|
|
1455 |
assert(fieldID != 0);
|
|
1456 |
jObject = (*env)->GetObjectField(env, jParam, fieldID);
|
|
1457 |
jByteArrayToCKByteArray(env, jObject, &(ckParam.pPublicData2), &(ckParam.ulPublicDataLen2));
|
|
1458 |
|
|
1459 |
return ckParam ;
|
|
1460 |
}
|