/*
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment:
*
* "This product includes software developed by IAIK of Graz University of
* Technology."
*
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Graz University of Technology" and "IAIK of Graz University of
* Technology" must not be used to endorse or promote products derived from
* this software without prior written permission.
*
* 5. Products derived from this software may not be called
* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
* written permission of Graz University of Technology.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "pkcs11wrapper.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "sun_security_pkcs11_wrapper_PKCS11.h"
#ifdef P11_ENABLE_C_GENERATEKEY
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_GenerateKey
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate
* CK_ULONG ulCount
* @return jlong jKeyHandle CK_OBJECT_HANDLE_PTR phKey
*/
{
if (ckpFunctions == NULL) { return 0L; }
}
return 0L;
}
rv = (*ckpFunctions->C_GenerateKey)(ckSessionHandle, &ckMechanism, ckpAttributes, ckAttributesLength, &ckKeyHandle);
/* cheack, if we must give a initialization vector back to Java */
switch (ckMechanism.mechanism) {
case CKM_PBE_MD2_DES_CBC:
case CKM_PBE_MD5_DES_CBC:
case CKM_PBE_MD5_CAST_CBC:
case CKM_PBE_MD5_CAST3_CBC:
case CKM_PBE_MD5_CAST128_CBC:
/* case CKM_PBE_MD5_CAST5_CBC: the same as CKM_PBE_MD5_CAST128_CBC */
case CKM_PBE_SHA1_CAST128_CBC:
/* case CKM_PBE_SHA1_CAST5_CBC: the same as CKM_PBE_SHA1_CAST128_CBC */
/* we must copy back the initialization vector to the jMechanism object */
break;
}
}
}
return jKeyHandle ;
}
#endif
#ifdef P11_ENABLE_C_GENERATEKEYPAIR
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_GenerateKeyPair
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)[J
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism
* @param jobjectArray jPublicKeyTemplate CK_ATTRIBUTE_PTR pPublicKeyTemplate
* CK_ULONG ulPublicKeyAttributeCount
* @param jobjectArray jPrivateKeyTemplate CK_ATTRIBUTE_PTR pPrivateKeyTemplate
* CK_ULONG ulPrivateKeyAttributeCount
* @return jlongArray jKeyHandles CK_OBJECT_HANDLE_PTR phPublicKey
* CK_OBJECT_HANDLE_PTR phPublicKey
*/
{
if (ckpKeyHandles == NULL) {
}
return NULL;
}
jAttributeArrayToCKAttributeArray(env, jPublicKeyTemplate, &ckpPublicKeyAttributes, &ckPublicKeyAttributesLength);
}
return NULL;
}
jAttributeArrayToCKAttributeArray(env, jPrivateKeyTemplate, &ckpPrivateKeyAttributes, &ckPrivateKeyAttributesLength);
}
return NULL;
}
}
}
return jKeyHandles ;
}
#endif
#ifdef P11_ENABLE_C_WRAPKEY
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_WrapKey
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;JJ)[B
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism
* @param jlong jWrappingKeyHandle CK_OBJECT_HANDLE hWrappingKey
* @param jlong jKeyHandle CK_OBJECT_HANDLE hKey
* @return jbyteArray jWrappedKey CK_BYTE_PTR pWrappedKey
* CK_ULONG_PTR pulWrappedKeyLen
*/
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jWrappingKeyHandle, jlong jKeyHandle)
{
rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength);
if (rv == CKR_BUFFER_TOO_SMALL) {
if (ckpWrappedKey == NULL) {
}
return NULL;
}
rv = (*ckpFunctions->C_WrapKey)(ckSessionHandle, &ckMechanism, ckWrappingKeyHandle, ckKeyHandle, ckpWrappedKey, &ckWrappedKeyLength);
}
}
}
return jWrappedKey ;
}
#endif
#ifdef P11_ENABLE_C_UNWRAPKEY
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_UnwrapKey
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J[B[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism
* @param jlong jUnwrappingKeyHandle CK_OBJECT_HANDLE hUnwrappingKey
* @param jbyteArray jWrappedKey CK_BYTE_PTR pWrappedKey
* CK_ULONG_PTR pulWrappedKeyLen
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate
* CK_ULONG ulCount
* @return jlong jKeyHandle CK_OBJECT_HANDLE_PTR phKey
*/
{
if (ckpFunctions == NULL) { return 0L; }
}
return 0L;
}
}
return 0L;
}
#if 0
/* cheack, if we must give a initialization vector back to Java */
/* we must copy back the unwrapped key info to the jMechanism object */
}
#endif
}
}
return jKeyHandle ;
}
#endif
#ifdef P11_ENABLE_C_DERIVEKEY
CK_SSL3_MASTER_KEY_DERIVE_PARAMS *params = (CK_SSL3_MASTER_KEY_DERIVE_PARAMS *) ckMechanism->pParameter;
return;
}
}
}
}
}
return;
}
}
}
}
/*
* Copy back the PRF output to Java.
*/
{
int i;
/* get mechanism */
if (jMechanismClass == NULL) { return; }
/* we do not have maching types, this should not occur */
return;
}
/* get the native CK_TLS_PRF_PARAMS */
if (ckTLSPrfParams != NULL_PTR) {
/* get the Java CK_TLS_PRF_PARAMS object (pParameter) */
/* copy back the client IV */
if (jTLSPrfParamsClass == NULL) { return; }
// Note: we assume that the token returned exactly as many bytes as we
// requested. Anything else would not make sense.
/* copy the bytes to the Java buffer */
for (i=0; i < jLength; i++) {
}
/* copy back the Java buffer to the object */
}
// free malloc'd data
}
}
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_DeriveKey
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism
* @param jlong jBaseKeyHandle CK_OBJECT_HANDLE hBaseKey
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate
* CK_ULONG ulCount
* @return jlong jKeyHandle CK_OBJECT_HANDLE_PTR phKey
*/
(JNIEnv *env, jobject obj, jlong jSessionHandle, jobject jMechanism, jlong jBaseKeyHandle, jobjectArray jTemplate)
{
if (ckpFunctions == NULL) { return 0L; }
}
return 0L;
}
switch (ckMechanism.mechanism) {
case CKM_TLS_PRF:
// these mechanism do not return a key handle via phKey
// set to NULL in case pedantic implementations check for it
break;
default:
// empty
break;
}
switch (ckMechanism.mechanism) {
/* we must copy back the client version */
break;
break;
/* we must copy back the unwrapped key info to the jMechanism object */
break;
case CKM_TLS_PRF:
break;
case CKM_ECDH1_DERIVE:
break;
default:
// empty
break;
}
}
return jKeyHandle ;
}
/*
* Copy back the client version information from the native
* structure to the Java object. This is only used for the
* CKM_SSL3_MASTER_KEY_DERIVE mechanism when used for deriving a key.
*
*/
{
/* get mechanism */
if (jMechanismClass == NULL) { return; }
/* we do not have maching types, this should not occur */
return;
}
/* get the native CK_SSL3_MASTER_KEY_DERIVE_PARAMS */
if (ckSSL3MasterKeyDeriveParams != NULL_PTR) {
/* get the native CK_VERSION */
/* get the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS (pParameter) */
/* get the Java CK_VERSION */
if (jSSL3MasterKeyDeriveParamsClass == NULL) { return; }
fieldID = (*env)->GetFieldID(env, jSSL3MasterKeyDeriveParamsClass, "pVersion", "L"CLASS_VERSION";");
/* now copy back the version from the native structure to the Java structure */
/* copy back the major version */
if (jVersionClass == NULL) { return; }
/* copy back the minor version */
}
}
}
/*
* Copy back the derived keys and initialization vectors from the native
* structure to the Java object. This is only used for the
* CKM_SSL3_KEY_AND_MAC_DERIVE mechanism when used for deriving a key.
*
*/
{
int i;
/* get mechanism */
if (jMechanismClass == NULL) { return; }
/* we do not have maching types, this should not occur */
return;
}
/* get the native CK_SSL3_KEY_MAT_PARAMS */
if (ckSSL3KeyMatParam != NULL_PTR) {
// free malloc'd data
}
}
/* get the native CK_SSL3_KEY_MAT_OUT */
if (ckSSL3KeyMatOut != NULL_PTR) {
/* get the Java CK_SSL3_KEY_MAT_PARAMS (pParameter) */
/* get the Java CK_SSL3_KEY_MAT_OUT */
if (jSSL3KeyMatParamsClass == NULL) { return; }
fieldID = (*env)->GetFieldID(env, jSSL3KeyMatParamsClass, "pReturnedKeyMaterial", "L"CLASS_SSL3_KEY_MAT_OUT";");
/* now copy back all the key handles and the initialization vectors */
/* copy back client MAC secret handle */
if (jSSL3KeyMatOutClass == NULL) { return; }
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hClientMacSecret));
/* copy back server MAC secret handle */
(*env)->SetLongField(env, jSSL3KeyMatOut, fieldID, ckULongToJLong(ckSSL3KeyMatOut->hServerMacSecret));
/* copy back client secret key handle */
/* copy back server secret key handle */
/* copy back the client IV */
/* copy the bytes to the Java buffer */
for (i=0; i < jLength; i++) {
}
/* copy back the Java buffer to the object */
}
// free malloc'd data
/* copy back the server IV */
/* copy the bytes to the Java buffer */
for (i=0; i < jLength; i++) {
}
/* copy back the Java buffer to the object */
}
// free malloc'd data
}
}
}
#endif