Pkcs#11 with NCryptoki error N. 145

0

I'm using the NCryptoki dll to manage the acccess to our HSMs.

I use a C# windows service. This service is a socket: it listens for requests and it access to the HSMs, doing stuff.

Using my code to acccess HSM, I 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?

I found 145 is 0x00000091 CKR_OPERATION_NOT_INITIALIZED: There is no active operation of an appropriate type in the specified session

I get this error, for example, when I call the find method:

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

It seems like the session isn't valid.

Our service is a listening socket. It gets a big load of requests and, few of them, fail with this message. Do you know why?

The weird point is the same request rarely fails and all the other times works.

c#
security
cryptography
pkcs#11
hsm
asked on Stack Overflow Apr 26, 2017 by Piero Alberto

1 Answer

1

You are most likely not using PKCS#11 library and PKCS#11 sessions in multi-threaded environment correctly. See my older answer to similar question for more details.

answered on Stack Overflow Apr 26, 2017 by jariq • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0