Index: cackey.c ================================================================== --- cackey.c +++ cackey.c @@ -3177,16 +3177,10 @@ CACKEY_DEBUG_PRINTF("Error. Some, but not All threading primitives provided."); return(CKR_ARGUMENTS_BAD); } } - - if (args->pReserved != NULL) { - CACKEY_DEBUG_PRINTF("Error. pReserved is not NULL."); - - return(CKR_ARGUMENTS_BAD); - } } else { cackey_args.CreateMutex = NULL; cackey_args.DestroyMutex = NULL; cackey_args.LockMutex = NULL; cackey_args.UnlockMutex = NULL; @@ -4976,10 +4970,11 @@ } CK_DEFINE_FUNCTION(CK_RV, C_Decrypt)(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDataLen, CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen) { CK_ULONG datalen_update, datalen_final; CK_RV decrypt_ret; + int mutex_retval; CACKEY_DEBUG_PRINTF("Called."); if (!cackey_initialized) { CACKEY_DEBUG_PRINTF("Error. Not initialized."); @@ -4996,10 +4991,46 @@ datalen_update = *pulDataLen; decrypt_ret = C_DecryptUpdate(hSession, pEncryptedData, ulEncryptedDataLen, pData, &datalen_update); if (decrypt_ret != CKR_OK) { CACKEY_DEBUG_PRINTF("Error. DecryptUpdate() returned failure (rv = %lu).", (unsigned long) decrypt_ret); + + if (decrypt_ret != CKR_BUFFER_TOO_SMALL) { + /* Terminate decryption operation */ + + mutex_retval = cackey_mutex_lock(cackey_biglock); + if (mutex_retval != 0) { + CACKEY_DEBUG_PRINTF("Error. Locking failed."); + + return(CKR_GENERAL_ERROR); + } + + if (!cackey_sessions[hSession].active) { + cackey_mutex_unlock(cackey_biglock); + + CACKEY_DEBUG_PRINTF("Error. Session not active."); + + return(CKR_SESSION_HANDLE_INVALID); + } + + if (!cackey_sessions[hSession].decrypt_active) { + cackey_mutex_unlock(cackey_biglock); + + CACKEY_DEBUG_PRINTF("Error. Decrypt not active."); + + return(CKR_OPERATION_NOT_INITIALIZED); + } + + cackey_sessions[hSession].decrypt_active = 0; + + mutex_retval = cackey_mutex_unlock(cackey_biglock); + if (mutex_retval != 0) { + CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); + + return(CKR_GENERAL_ERROR); + } + } return(decrypt_ret); } if (pData) { @@ -5373,10 +5404,11 @@ } CK_DEFINE_FUNCTION(CK_RV, C_Sign)(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) { unsigned long start_sign_bufused; CK_RV sign_ret; + int mutex_retval; CACKEY_DEBUG_PRINTF("Called."); if (!cackey_initialized) { CACKEY_DEBUG_PRINTF("Error. Not initialized."); @@ -5393,10 +5425,44 @@ start_sign_bufused = cackey_sessions[hSession].sign_bufused; sign_ret = C_SignUpdate(hSession, pData, ulDataLen); if (sign_ret != CKR_OK) { CACKEY_DEBUG_PRINTF("Error. SignUpdate() returned failure (rv = %lu).", (unsigned long) sign_ret); + + if (sign_ret != CKR_BUFFER_TOO_SMALL) { + mutex_retval = cackey_mutex_lock(cackey_biglock); + if (mutex_retval != 0) { + CACKEY_DEBUG_PRINTF("Error. Locking failed."); + + return(CKR_GENERAL_ERROR); + } + + if (!cackey_sessions[hSession].active) { + cackey_mutex_unlock(cackey_biglock); + + CACKEY_DEBUG_PRINTF("Error. Session not active."); + + return(CKR_SESSION_HANDLE_INVALID); + } + + if (!cackey_sessions[hSession].sign_active) { + cackey_mutex_unlock(cackey_biglock); + + CACKEY_DEBUG_PRINTF("Error. Sign not active."); + + return(CKR_OPERATION_NOT_INITIALIZED); + } + + cackey_sessions[hSession].sign_active = 0; + + mutex_retval = cackey_mutex_unlock(cackey_biglock); + if (mutex_retval != 0) { + CACKEY_DEBUG_PRINTF("Error. Unlocking failed."); + + return(CKR_GENERAL_ERROR); + } + } return(sign_ret); } sign_ret = C_SignFinal(hSession, pSignature, pulSignatureLen); Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1,6 +1,6 @@ -AC_INIT(cackey, 0.5.19) +AC_INIT(cackey, 0.5.20) AC_CONFIG_HEADERS(config.h) dnl Locate standard tools AC_PROG_CC AC_PROG_MAKE_SET Index: pkcs11/pkcs11t.h ================================================================== --- pkcs11/pkcs11t.h +++ pkcs11/pkcs11t.h @@ -1023,11 +1023,10 @@ CK_CREATEMUTEX CreateMutex; CK_DESTROYMUTEX DestroyMutex; CK_LOCKMUTEX LockMutex; CK_UNLOCKMUTEX UnlockMutex; CK_FLAGS flags; - CK_VOID_PTR LibraryParameters; CK_VOID_PTR pReserved; } CK_C_INITIALIZE_ARGS; /* flags: bit flags that provide capabilities of the slot * Bit Flag Mask Meaning Index: test.c ================================================================== --- test.c +++ test.c @@ -123,11 +123,10 @@ initargs.DestroyMutex = NULL; initargs.LockMutex = NULL; initargs.UnlockMutex = NULL; initargs.flags = CKF_OS_LOCKING_OK; initargs.pReserved = NULL; - initargs.LibraryParameters = NULL; chk_rv = C_Initialize(&initargs); if (chk_rv != CKR_OK) { initargs.CreateMutex = NULL; initargs.DestroyMutex = NULL;