/*
*/
/* 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"
/* The list of notify callback handles that are currently active and waiting
* for callbacks from their sessions.
*/
#ifndef NO_CALLBACKS
#endif /* NO_CALLBACKS */
#ifdef P11_ENABLE_C_OPENSESSION
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_OpenSession
* Parametermapping: *PKCS11*
* @param jlong jSlotID CK_SLOT_ID slotID
* @param jlong jFlags CK_FLAGS flags
* @param jobject jApplication CK_VOID_PTR pApplication
* @param jobject jNotify CK_NOTIFY Notify
* @return jlong jSessionHandle CK_SESSION_HANDLE_PTR phSession
*/
{
#ifndef NO_CALLBACKS
#endif /* NO_CALLBACKS */
if (ckpFunctions == NULL) { return 0L; }
#ifndef NO_CALLBACKS
if (notifyEncapsulation == NULL) {
return 0L;
}
: NULL;
} else {
}
#else
#endif /* NO_CALLBACKS */
TRACE0("DEBUG: C_OpenSession");
TRACE0(" ... ");
#ifndef NO_CALLBACKS
if (notifyEncapsulation != NULL) {
}
}
#endif /* NO_CALLBACKS */
return 0L;
}
TRACE0("got session");
TRACE0(" ... ");
#ifndef NO_CALLBACKS
if (notifyEncapsulation != NULL) {
/* store the notifyEncapsulation to enable later cleanup */
}
#endif /* NO_CALLBACKS */
TRACE0("FINISHED\n");
return jSessionHandle ;
}
#endif
#ifdef P11_ENABLE_C_CLOSESESSION
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_CloseSession
* Signature: (J)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
*/
{
#ifndef NO_CALLBACKS
#endif /* NO_CALLBACKS */
if (ckpFunctions == NULL) { return; }
#ifndef NO_CALLBACKS
if (notifyEncapsulation != NULL) {
/* there was a notify object used with this session, now dump the
* encapsulation object
*/
if (jApplicationData != NULL) {
}
}
#endif /* NO_CALLBACKS */
}
#endif
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_CloseAllSessions
* Signature: (J)V
* Parametermapping: *PKCS11*
* @param jlong jSlotID CK_SLOT_ID slotID
*/
{
#ifndef NO_CALLBACKS
#endif /* NO_CALLBACKS */
if (ckpFunctions == NULL) { return; }
#ifndef NO_CALLBACKS
/* Remove all notify callback helper objects. */
/* there was a notify object used with this session, now dump the
* encapsulation object
*/
if (jApplicationData != NULL) {
}
}
#endif /* NO_CALLBACKS */
}
#endif
#ifdef P11_ENABLE_C_GETSESSIONINFO
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_GetSessionInfo
* Signature: (J)Lsun/security/pkcs11/wrapper/CK_SESSION_INFO;
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @return jobject jSessionInfo CK_SESSION_INFO_PTR pInfo
*/
{
}
return jSessionInfo ;
}
#endif
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_GetOperationState
* Signature: (J)[B
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @return jbyteArray jState CK_BYTE_PTR pOperationState
* CK_ULONG_PTR pulOperationStateLen
*/
{
return NULL;
}
}
return jState ;
}
#endif
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_SetOperationState
* Signature: (J[BJJ)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jbyteArray jOperationState CK_BYTE_PTR pOperationState
* CK_ULONG ulOperationStateLen
* @param jlong jEncryptionKeyHandle CK_OBJECT_HANDLE hEncryptionKey
* @param jlong jAuthenticationKeyHandle CK_OBJECT_HANDLE hAuthenticationKey
*/
(JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jOperationState, jlong jEncryptionKeyHandle, jlong jAuthenticationKeyHandle)
{
if (ckpFunctions == NULL) { return; }
rv = (*ckpFunctions->C_SetOperationState)(ckSessionHandle, ckpState, ckStateLength, ckEncryptionKeyHandle, ckAuthenticationKeyHandle);
}
#endif
#ifdef P11_ENABLE_C_LOGIN
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_Login
* Signature: (JJ[C)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jlong jUserType CK_USER_TYPE userType
* @param jcharArray jPin CK_CHAR_PTR pPin
* CK_ULONG ulPinLen
*/
{
if (ckpFunctions == NULL) { return; }
}
#endif
#ifdef P11_ENABLE_C_LOGOUT
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_Logout
* Signature: (J)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
*/
{
if (ckpFunctions == NULL) { return; }
}
#endif
/* ************************************************************************** */
/* Functions for keeping track of notify callbacks */
/* ************************************************************************** */
#ifndef NO_CALLBACKS
/*
* Add the given notify encapsulation object to the list of active notify
* objects.
* If notifyEncapsulation is NULL, this function does nothing.
*/
void putNotifyEntry(JNIEnv *env, CK_SESSION_HANDLE hSession, NotifyEncapsulation *notifyEncapsulation) {
if (notifyEncapsulation == NULL) {
return;
}
return;
}
if (notifyListHead == NULL) {
/* this is the first entry */
} else {
/* go to the last entry; i.e. the first node which's 'next' is NULL.
*/
}
}
}
/*
* Removes the active notifyEncapsulation object used with the given session and
* returns it. If there is no notifyEncapsulation active for this session, this
* function returns NULL.
*/
if (notifyListHead == NULL) {
/* this is the first entry */
} else {
/* Find the node with the wanted session handle. Also stop, when we reach
* the last entry; i.e. the first node which's 'next' is NULL.
*/
previousNode = NULL;
}
/* We found a entry for the wanted session, now remove it. */
if (previousNode == NULL) {
/* it's the first node */
} else {
}
} else {
/* We did not find a entry for this session */
}
}
return notifyEncapsulation ;
}
/*
* Removes the first notifyEncapsulation object. If there is no notifyEncapsulation,
* this function returns NULL.
*/
if (notifyListHead == NULL) {
/* this is the first entry */
} else {
/* Remove the first entry. */
}
return notifyEncapsulation ;
}
#endif /* NO_CALLBACKS */
#ifndef NO_CALLBACKS
/*
* The function handling notify callbacks. It casts the pApplication paramter
* back to a NotifyEncapsulation structure and retrieves the Notify object and
* the application data from it.
*
* @param hSession The session, this callback is comming from.
* @param event The type of event that occurred.
* @param pApplication The application data as passed in upon OpenSession. In
this wrapper we always pass in a NotifyEncapsulation
object, which holds necessary information for delegating
the callback to the Java VM.
* @return
*/
)
{
/* Get the currently running Java VM */
/* Determine, if current thread is already attached */
if (returnValue == JNI_EDETACHED) {
/* thread detached, so attach it */
wasAttached = 0;
} else if (returnValue == JNI_EVERSION) {
/* this version of JNI is not supported, so just try to attach */
/* we assume it was attached to ensure that this thread is not detached
* afterwards even though it should not
*/
wasAttached = 1;
} else {
/* attached */
wasAttached = 1;
}
/* check, if callback threw an exception */
if (pkcs11Exception != NULL) {
/* TBD: clear the pending exception with ExceptionClear? */
/* The was an exception thrown, now we get the error-code from it */
}
/* if we attached this thread to the VM just for callback, we detach it now */
if (wasAttached) {
}
return rv ;
}
#endif /* NO_CALLBACKS */