/*
*/
/* 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_SIGNINIT
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_SignInit
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism
* @return jlong jKeyHandle CK_OBJECT_HANDLE hKey
*/
{
if (ckpFunctions == NULL) { return; }
}
}
#endif
#ifdef P11_ENABLE_C_SIGN
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_Sign
* Signature: (J[B)[B
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jbyteArray jData CK_BYTE_PTR pData
* CK_ULONG ulDataLen
* @return jbyteArray jSignature CK_BYTE_PTR pSignature
* CK_ULONG_PTR pulSignatureLen
*/
{
/* START standard code */
/* first determine the length of the signature */
return NULL;
}
if (ckpSignature == NULL) {
return NULL;
}
/* now get the signature */
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength);
/* END standard code */
/* START workaround code for operation abort bug in pkcs#11 of Datakey and iButton */
/*
ckpSignature = (CK_BYTE_PTR) malloc(256 * sizeof(CK_BYTE));
if (ckpSignature == NULL) {
free(ckpData);
JNU_ThrowOutOfMemoryError(env, 0);
return NULL;
}
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength);
if (rv == CKR_BUFFER_TOO_SMALL) {
free(ckpSignature);
ckpSignature = (CK_BYTE_PTR) malloc(ckSignatureLength * sizeof(CK_BYTE));
if (ckpSignature == NULL) {
free(ckpData);
JNU_ThrowOutOfMemoryError(env, 0);
return NULL;
}
rv = (*ckpFunctions->C_Sign)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, &ckSignatureLength);
}
*/
/* END workaround code */
}
return jSignature ;
}
#endif
#ifdef P11_ENABLE_C_SIGNUPDATE
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_SignUpdate
* Signature: (J[BII)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jbyteArray jPart CK_BYTE_PTR pPart
* CK_ULONG ulPartLen
*/
(JNIEnv *env, jobject obj, jlong jSessionHandle, jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen)
{
if (ckpFunctions == NULL) { return; }
if (directIn != 0) {
return;
}
if (jInLen <= MAX_STACK_BUFFER_LEN) {
} else {
return;
}
}
while (jInLen > 0) {
return;
}
}
return;
}
}
}
#endif
#ifdef P11_ENABLE_C_SIGNFINAL
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_SignFinal
* Signature: (J)[B
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @return jbyteArray jSignature CK_BYTE_PTR pSignature
* CK_ULONG_PTR pulSignatureLen
*/
{
}
if (rv == CKR_BUFFER_TOO_SMALL) {
return NULL;
}
}
}
return jSignature;
}
#endif
#ifdef P11_ENABLE_C_SIGNRECOVERINIT
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_SignRecoverInit
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism
* @return jlong jKeyHandle CK_OBJECT_HANDLE hKey
*/
{
if (ckpFunctions == NULL) { return; }
}
}
#endif
#ifdef P11_ENABLE_C_SIGNRECOVER
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_SignRecover
* Signature: (J[BII[BII)I
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jbyteArray jData CK_BYTE_PTR pData
* CK_ULONG ulDataLen
* @return jbyteArray jSignature CK_BYTE_PTR pSignature
* CK_ULONG_PTR pulSignatureLen
*/
(JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jIn, jint jInOfs, jint jInLen, jbyteArray jOut, jint jOutOfs, jint jOutLen)
{
if (ckpFunctions == NULL) { return 0; }
if (jInLen <= MAX_STACK_BUFFER_LEN) {
} else {
return 0;
}
}
return 0;
}
/* re-alloc larger buffer if it fits into our Java buffer */
}
return 0;
}
}
}
return ckSignatureLength;
}
#endif
#ifdef P11_ENABLE_C_VERIFYINIT
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_VerifyInit
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism
* @return jlong jKeyHandle CK_OBJECT_HANDLE hKey
*/
{
if (ckpFunctions == NULL) { return; }
}
}
#endif
#ifdef P11_ENABLE_C_VERIFY
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_Verify
* Signature: (J[B[B)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jbyteArray jData CK_BYTE_PTR pData
* CK_ULONG ulDataLen
* @param jbyteArray jSignature CK_BYTE_PTR pSignature
* CK_ULONG_PTR pulSignatureLen
*/
{
if (ckpFunctions == NULL) { return; }
return;
}
/* verify the signature */
rv = (*ckpFunctions->C_Verify)(ckSessionHandle, ckpData, ckDataLength, ckpSignature, ckSignatureLength);
}
#endif
#ifdef P11_ENABLE_C_VERIFYUPDATE
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_VerifyUpdate
* Signature: (J[BII)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jbyteArray jPart CK_BYTE_PTR pPart
* CK_ULONG ulPartLen
*/
(JNIEnv *env, jobject obj, jlong jSessionHandle, jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen)
{
if (ckpFunctions == NULL) { return; }
if (directIn != 0) {
return;
}
if (jInLen <= MAX_STACK_BUFFER_LEN) {
} else {
return;
}
}
while (jInLen > 0) {
return;
}
return;
}
}
}
#endif
#ifdef P11_ENABLE_C_VERIFYFINAL
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_VerifyFinal
* Signature: (J[B)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jbyteArray jSignature CK_BYTE_PTR pSignature
* CK_ULONG ulSignatureLen
*/
{
if (ckpFunctions == NULL) { return; }
/* verify the signature */
}
#endif
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_VerifyRecoverInit
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism
* @return jlong jKeyHandle CK_OBJECT_HANDLE hKey
*/
{
if (ckpFunctions == NULL) { return; }
}
}
#endif
#ifdef P11_ENABLE_C_VERIFYRECOVER
/*
* Class: sun_security_pkcs11_wrapper_PKCS11
* Method: C_VerifyRecover
* Signature: (J[BII[BII)I
* Parametermapping: *PKCS11*
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession
* @param jbyteArray jSignature CK_BYTE_PTR pSignature
* CK_ULONG ulSignatureLen
* @return jbyteArray jData CK_BYTE_PTR pData
* CK_ULONG_PTR pulDataLen
*/
(JNIEnv *env, jobject obj, jlong jSessionHandle, jbyteArray jIn, jint jInOfs, jint jInLen, jbyteArray jOut, jint jOutOfs, jint jOutLen)
{
if (ckpFunctions == NULL) { return 0; }
if (jInLen <= MAX_STACK_BUFFER_LEN) {
} else {
return 0;
}
}
return 0;
}
/* re-alloc larger buffer if it fits into our Java buffer */
return 0;
}
}
}
return ckDataLength;
}
#endif