Cryptware.NCryptoki.CryptokiException: Error n. 145

4/21/2017 3:52:02 PM
Gravatar
Total Posts 33

Cryptware.NCryptoki.CryptokiException: Error n. 145

Hi all,

using our code to acccess HSM, we randomly get this message:

Cryptware.NCryptoki.CryptokiException: Error n. 145

 

Only few calls on the total get this message, but it is quite annoying. Do you know why this is happening?

4/21/2017 4:20:39 PM
Gravatar
Total Posts 30

Re: Cryptware.NCryptoki.CryptokiException: Error n. 145

145 is 0x00000091 CKR_OPERATION_NOT_INITIALIZED

Usually this error happen when you call an operation as, for example, Sign without calling SignInit.

Are you working with different thread?

Consider that the SignInit, Sign, SignFinal should be used together as an atomic operation

 

4/26/2017 10:57:07 AM
Gravatar
Total Posts 33

Re: Cryptware.NCryptoki.CryptokiException: Error n. 145

Thanks for the reply and excuse me for my delay.

I get this error always at the same line code when I call the find method:

Cryptware.NCryptoki.CryptokiException: Error n. 145 at Cryptware.NCryptoki.CryptokiObjects.Find(CryptokiCollection attList, Int32 nMaxCount)

 

I don't use SignInit, Sign, SignFinal but as you can see, I call the Find method. Maybe does this method use that functions?

 

Can you please give more hints?

4/26/2017 2:31:19 PM
Gravatar
Total Posts 33

Re: Cryptware.NCryptoki.CryptokiException: Error n. 145

I just found this:

 

CKR_HOST_MEMORY error (due to too many PKCS11 sessions being opened) (Note: however, this error sometimes does not show up at the top level for some unknown reason) C_EncryptUpdate() <-

CKR_OPERATION_NOT_INITIALIZED (since the previous failing C_EncryptUpdate() call terminates the operation and would require re-initialization again)

 

Is it right? If yes, how can avoid it? We have a lot of access to our HSM, but I don't know if this is the model case... I mean, in our socket service, we listen for requests and then access to the HSM, but the Session is only one, used for all the purposes

4/27/2017 12:27:57 PM
Gravatar
Total Posts 30

Re: Cryptware.NCryptoki.CryptokiException: Error n. 145

CKR_OPERATION_NOT_INITIALIZED happens also on C_FindObjectsInit, C_FindObjects, C_FindObjectsFinal operation.

the method you called

CryptokiObjects.Find 

internally calls C_FindObjectsInit, C_FindObjects, C_FindObjectsFinal.

If you are strongly using multithreading, and you are calling this method in different threads at different (random) moments it's better that you synchronize such calls.

 

 

11/16/2017 9:49:34 AM
Gravatar
Total Posts 33

Re: Cryptware.NCryptoki.CryptokiException: Error n. 145

What does it mean?

 

I have a socket service receiving requests from my softwares. These call are different and I have a unique instance of "Session" in my socket service.

 

Can this be a problem? If yes, how can I fix it?

11/16/2017 11:01:03 AM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Cryptware.NCryptoki.CryptokiException: Error n. 145

The error you got is 

CKR_OPERATION_NOT_INITIALIZED

This happens when the function Cryptoki.Initialize is not called.

In your case it seems as you have a Session object that becomes to a not initialized Cryptoki instance.

Maybe you called Cryptoki.Finalize in some place.

 

11/20/2017 8:28:03 AM
Gravatar
Total Posts 33

Re: Cryptware.NCryptoki.CryptokiException: Error n. 145

Since I have a unique instance of the Session object, how have I to do it? 
 

Every time I use my Session, maybe? Further, synchronous accesses with the same Session variables, can be a problem, in this case?