Cryptware.NCryptoki.CryptokiException: Error n. 224

5/27/2013 4:39:02 PM
Gravatar
Total Posts 7

Cryptware.NCryptoki.CryptokiException: Error n. 224

I am wondering what does this error means, and also if a correlation table for errors exist somewhere, thank you.

5/27/2013 4:41:47 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

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

Hi,

the list of PKCS#11 errors is here:

http://wiki.ncryptoki.com/How-NCryptoki-manages-PKCS-11-errors.ashx

 

error 224 means:

CKR_TOKEN_NOT_PRESENT

5/27/2013 4:56:24 PM
Gravatar
Total Posts 7

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

Ok, so.. this error is throwing sometimes for a couple of users when trying to get the TokenInfo for an active slot, please refer to this code:

             foreach (Slot slot in _cryptoki.ActiveSlots)

                {
                    TokenInfo tokenInfo;
                    try
                    {
                        tokenInfo = slot.Token.Info; // Error 224 here
                    }
                    catch (CryptokiException ex)
                    {
                        if (ex.ErrorCode != CryptokiException.CKR_TOKEN_NOT_RECOGNIZED)
                            throw;

                        continue;
                    }
                }

 

Do you have any suggestions for this?

 

Thank you

5/27/2013 5:17:25 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

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

This error comes from the underlying PKCS#11 module. NCryptoki simply returns what the underlying module returns back.

Are you working in a multithread process? i.e.are you calling that piece of code in different threads?

If so this may cause this strange problem. Try to initialize the Cryptoki object by passing true to say to the underlying PKCS#11 module to work in multithreading:

cryptoki.Initialize(true);

 

 

5/27/2013 7:18:41 PM
Gravatar
Total Posts 5

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

I'm having the same problem with SafeSign PKCS#11.

When I execute a openSession with the parameters CKF_SERIAL_SESSION and CKF_RW_SESSION and I use eTPKCS11.dll (Safenet) it works very well, but the same line with aetpkcss1.dll (SafeSign) I receive the E0 error (TOKEN_NOT_PRESENT) but I can get Slot infomation. :(

 

               // SAfenet -> Cryptoki cryptoki = new Cryptoki("eTPKCS11.dll");
                Cryptoki cryptoki = new Cryptoki("aetpkss1.dll");

                cryptoki.Initialize(true);

                SlotList list = cryptoki.ActiveSlots;

                SlotInfo info = list[0].Info;

                // Safenet -> session = cryptoki.Slots[0].Token.OpenSession(Session.CKF_SERIAL_SESSION | Session.CKF_RW_SESSION, null, null);
                session = cryptoki.Slots[0].Token.OpenSession(Session.CKF_SERIAL_SESSION | Session.CKF_RW_SESSION, null, null);
 

I will appreciate any tip.

Thanks

Eder Souza

5/27/2013 10:05:06 PM
Gravatar
Total Posts 5

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

I solved my problem. Safesign has a lot of slots but only one will have the token present. I needed to check in what slot the token is inserted.
Below follow the code.

 

            Session session = null;
            Cryptoki cryptoki = null;
            try
            {
                
                cryptoki = new Cryptoki("aetpkss1.dll");
                
                int ret = cryptoki.Initialize(true);
                if (ret != 0)
                {
                    MessageBox.Show("Erro: " + ret);
                    return;
                }

                SlotList slots = cryptoki.Slots;
                if (slots.Count == 0)
                {
                    throw new Exception("Não existe slots disponíveis...");
                }
                Slot slot = null;
                int slotNumber = 0;
                for (int i = 0; i < slots.Count; i++)
                {
                    slot = slots[i];
                    if (slot.IsTokenPresent)
                    {
                        slotNumber = i;
                        break;
                    }

                }

                if (!slot.IsTokenPresent)
                {
                    throw new Exception("Não existe token presente...");
                }
                Token token = slot.Token;
                TokenInfo info = token.Info;
                txtCSR.Text = "Firmare Version: " + info.FirmwareVersion + Environment.NewLine + Environment.NewLine + "Memória livre: " + info.FreePrivateMemory + Environment.NewLine + "Hardware Version: " + info.HardwareVersion + Environment.NewLine + "Manufacture ID: " + info.ManufacturerID;


                session = cryptoki.Slots[slotNumber].Token.OpenSession(Session.CKF_SERIAL_SESSION|Session.CKF_RW_SESSION, null, null);