/*
*/
/* 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_CREATEOBJECT
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_CreateObject
* Signature: (J[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate
* CK_ULONG ulCount
* @return jlong jObjectHandle CK_OBJECT_HANDLE_PTR phObject
*/
{
if (ckpFunctions == NULL) { return 0L; }
rv = (*ckpFunctions->C_CreateObject)(ckSessionHandle, ckpAttributes, ckAttributesLength, &ckObjectHandle);
return jObjectHandle ;
}
#endif
#ifdef P11_ENABLE_C_COPYOBJECT
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_CopyObject
* Signature: (JJ[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)J
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jlong jObjectHandle CK_OBJECT_HANDLE hObject
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate
* CK_ULONG ulCount
* @return jlong jNewObjectHandle CK_OBJECT_HANDLE_PTR phNewObject
*/
{
if (ckpFunctions == NULL) { return 0L; }
rv = (*ckpFunctions->C_CopyObject)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength, &ckNewObjectHandle);
return jNewObjectHandle ;
}
#endif
#ifdef P11_ENABLE_C_DESTROYOBJECT
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_DestroyObject
* Signature: (JJ)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jlong jObjectHandle CK_OBJECT_HANDLE hObject
*/
{
if (ckpFunctions == NULL) { return; }
}
#endif
#ifdef P11_ENABLE_C_GETOBJECTSIZE
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_GetObjectSize
* Signature: (JJ)J
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jlong jObjectHandle CK_OBJECT_HANDLE hObject
* @return jlong jObjectSize CK_ULONG_PTR pulSize
*/
{
if (ckpFunctions == NULL) { return 0L; }
return jObjectSize ;
}
#endif
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_GetAttributeValue
* Signature: (JJ[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jlong jObjectHandle CK_OBJECT_HANDLE hObject
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate
* CK_ULONG ulCount
*/
{
CK_ULONG i;
if (ckpFunctions == NULL) { return; }
TRACE0("DEBUG: C_GetAttributeValue");
TRACE0(" ... ");
TRACE2("DEBUG: jAttributeArrayToCKAttributeArray finished with ckpAttribute = %d, Length = %d\n", ckpAttributes, ckAttributesLength);
/* first set all pValue to NULL, to get the needed buffer length */
for(i = 0; i < ckAttributesLength; i++) {
}
}
rv = (*ckpFunctions->C_GetAttributeValue)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength);
return ;
}
/* now, the ulValueLength field of each attribute should hold the exact buffer length needed
* allocate the needed buffers accordingly
*/
for (i = 0; i < ckAttributesLength; i++) {
return;
}
}
/* now get the attributes with all values */
rv = (*ckpFunctions->C_GetAttributeValue)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength);
/* copy back the values to the Java attributes */
for (i = 0; i < ckAttributesLength; i++) {
if (jAttribute == NULL) {
return;
}
return;
}
}
}
TRACE0("FINISHED\n");
}
#endif
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_SetAttributeValue
* Signature: (JJ[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jlong jObjectHandle CK_OBJECT_HANDLE hObject
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate
* CK_ULONG ulCount
*/
{
if (ckpFunctions == NULL) { return; }
rv = (*ckpFunctions->C_SetAttributeValue)(ckSessionHandle, ckObjectHandle, ckpAttributes, ckAttributesLength);
}
#endif
#ifdef P11_ENABLE_C_FINDOBJECTSINIT
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_FindObjectsInit
* Signature: (J[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobjectArray jTemplate CK_ATTRIBUTE_PTR pTemplate
* CK_ULONG ulCount
*/
{
if (ckpFunctions == NULL) { return; }
TRACE0("DEBUG: C_FindObjectsInit");
TRACE0(" ... ");
TRACE0("FINISHED\n");
}
#endif
#ifdef P11_ENABLE_C_FINDOBJECTS
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_FindObjects
* Signature: (JJ)[J
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jlong jMaxObjectCount CK_ULONG ulMaxObjectCount
* @return jlongArray jObjectHandleArray CK_OBJECT_HANDLE_PTR phObject
* CK_ULONG_PTR pulObjectCount
*/
{
if (ckpObjectHandleArray == NULL) {
return NULL;
}
rv = (*ckpFunctions->C_FindObjects)(ckSessionHandle, ckpObjectHandleArray, ckMaxObjectLength, &ckActualObjectCount);
}
return jObjectHandleArray ;
}
#endif
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_FindObjectsFinal
* Signature: (J)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
*/
{
if (ckpFunctions == NULL) { return; }
}
#endif