Cryptoki dll causing application to crash

9/1/2014 9:54:12 AM
Gravatar
Total Posts 3

Cryptoki dll causing application to crash

Hi everyone,

 

I'm using cryptoki in a C# app. The problem I have is the following:

I initialize cryptoki using the following code:

public static bool InitializeCryptoki(string criptokilib)
  {
   if (cryptoki != null)
    throw new PdfSignException(PdfSignExceptionCode.PDF_EXCEPTION_NOT_FINALIZED);

   try
   {
    cryptoki = new Cryptoki(criptokilib);
                if (cryptoki.Initialize() == 0)
                {
                    isInitialized = true;
                    return true;
                }
                return false;
   }
   catch (CryptokiException ex)
   {
    Log.Log(log, LogState.ERROR, UserId, "Initialize", null, ex.Message);
    return false;
   }
  }

criptokilib value is equal to "eTPKCS11.dll".

 

After cryptoki is initialized, I check if at least one card reader exists using the following code:

 

public static bool HasCardReaders
  {
   get
   {
    if (cryptoki == null)
     throw new PdfSignException(PdfSignExceptionCode.PDF_EXCEPTION_NOT_INITIALIZED);
    return cryptoki.Slots.Count != 0;
   }
  }

 

When running the app in debug mode from the compiler (VS 2012), an error message is displayed (no app crash) saying that no card reader has been detected.

When running the app outside the compiler (VS 2012) - by double clicking the exe in debug folder, my application crashes. Looking at the log files, sometimes the app crashes while initializing cryptoki, and sometimes the app crashes while checking if at least one card reader exists.

In debug mode, I discovered that cryptoki.Slots[i].Token throws error n. 224. Can this error cause my app to crash? Do you have any idea how to overcame this issue?

 

Thank you very much,

Gica G.

9/1/2014 10:13:13 AM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Cryptoki dll causing application to crash

Error 224 (0xE0) means CKR_TOKEN_NOT_PRESENT.

You are trying to connect to a token in a slot that doesn't contain any token.

The list of the error messages is here: http://wiki.ncryptoki.com/How-NCryptoki-manages-PKCS-11-errors.ashx

 

Consider that NCryptoki is a wrapper to native PKCS#11 dll. Errors and crashes usually comes from the native dll.

 

9/1/2014 10:26:17 AM
Gravatar
Total Posts 3

Re: Cryptoki dll causing application to crash

Thank you for answering so quickly.

Ok, I understand why the error occurs, but is there something I can do so I can treat this error?

The fact that my app crashes is pretty severe.

Best regards,

Gica G.

9/1/2014 10:43:45 AM
Gravatar
Total Posts 3

Re: Cryptoki dll causing application to crash

Updating to the last Ncryptoki.dll seems to resolve this issue.

Thank you for your help,

 

Have a great day!