Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKR_OPERATION_NOT_INITIALIZED in multithreaded application #219

Open
BaerMitUmlaut opened this issue Feb 9, 2023 · 0 comments
Open

CKR_OPERATION_NOT_INITIALIZED in multithreaded application #219

BaerMitUmlaut opened this issue Feb 9, 2023 · 0 comments

Comments

@BaerMitUmlaut
Copy link

I'm working on a multithreaded application and I'm currently having some trouble with a CKR_OPERATION_NOT_INITIALIZED error thrown in the last line of this block:

CKR rv = _pkcs11Library.C_DecryptInit(_sessionId, ref ckMechanism, ConvertUtils.UInt32FromUInt64(keyHandle.ObjectId));
if (rv != CKR.CKR_OK)
throw new Pkcs11Exception("C_DecryptInit", rv);
NativeULong decryptedDataLen = 0;
rv = _pkcs11Library.C_Decrypt(_sessionId, encryptedData, ConvertUtils.UInt32FromInt32(encryptedData.Length), null, ref decryptedDataLen);
if (rv != CKR.CKR_OK)
throw new Pkcs11Exception("C_Decrypt", rv);

Screenshot

grafik

As far as I understand, this error is thrown when the encryption or decryption operation is not initialized and from what I've read, an operation stays initialized until data is decrypted. My best guess is that the following is happening:

Thread A Thread B Initialized
C_DecryptInit Yes
C_DecryptInit Yes
C_Decrypt No
C_Decrypt

Thus a lock would be required to make the call to Session.Encrypt / Session.Decrypt thread safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant