Hi all,

A few years ago I developed a smart card PKCS#11 module which integrates correctly with Mozilla Firefox in Linux and Windows. Everything worked perfectly until we also tried to access to this module from an applet. On Ubuntu Linux (Dapper), the PKCS#11 library accesses to another shared library that uses pcsc-lite 1.2.9 beta 9-1 to operate with the smart card. This library has to deal with the concurrency issues.

My problem arises when the applet executes, i.e. the second process to access smart card shared library (the first is the browser´s PKCS#11 instance). It tries to send data to the card and everything fails, I ilustrate this in the following lines:


                                               1- Browser´s instance

SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext)--> SCARD_S_SUCCESS

SCardListReaders(hContext, NULL, NULL, &cch))--> SCARD_S_SUCCESS

SCardConnect(hContext, lpReader, SCARD_SHARE_SHARED,SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard,&dwActiveProtocol)-->SCARD_S_SUCCESS

..... all operations SCardTransmit works ok....until applet´s instance enters ....


                                               2- Applet´s instance

SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext)--> SCARD_S_SUCCESS

SCardListReaders(hContext, NULL, NULL, &cch))--> SCARD_S_SUCCESS

SCardConnect(hContext, lpReader, SCARD_SHARE_SHARED,SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard,&dwActiveProtocol)-->SCARD_S_SUCCESS

.... and now almost all the operations of both instances with SCardTransmit returns error SCARD_W_RESET_CARD...


To disconnect the connection to the card, I use this code (which works ok with single process accessing the library):

   if (hContext != 0) {
       if (hContext)
           SCardReleaseContext(hContext);
       if (hsCard)
           SCardDisconnect(hsCard,SCARD_LEAVE_CARD);
   }

At the beginning, I thought that it was problem of concurrency management, but when I put each call to a method which uses SCardTransmit between (SCardBeginTransaction and SCardEndTransaction(hsCard, SCARD_LEAVE_CARD) (being careful of not make nestings between these instructions), I get confused because I didn't achieve best results. I got errors like 0x80100068 (card not connected), 0x80100009 (specified reader not recognized), 0x80100001 (consistency check failed)... what´s happening to my card!!??

After that, and focusing on the most frecuent error (SCARD_W_RESET_CARD), I tried to reconnect with the card after getting it, but I cannot reconnect successfully and I always get an INSUFFICIENT_BUFFER error in SCardTransmit.


   DWORD dwActiveProtocol = 0;
long lReturn; *status=new unsigned char[256];
   unsigned long dwStatusLength = sizeof(status);
   SCARD_IO_REQUEST pioRecvPci;
   unsigned long lpdwExtraBytes = 0;

lReturn = SCardTransmit(hsCard, SCARD_PCI_T0, apdu->bytes(), apdu->length(), NULL, *status, &dwStatusLength);

   /* Card has been reset by another application!!! */
   if ( lReturn == SCARD_W_RESET_CARD ) {
LogFilter2("sendAPDU. instancia: %ld ERROR SCARD_W_RESET_CARD\n",hsCard); lReturn = SCardReconnect( hsCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,SCARD_RESET_CARD, &dwActiveProtocol );

       if (lReturn == SCARD_S_SUCCESS){
       LogFilter2("sendAPDU. successfully reconnected\n",hsCard);
lReturn = SCardTransmit(hsCard, SCARD_PCI_T0, apdu->bytes(), apdu->length(), NULL, *status, &dwStatusLength);
           if (lReturn == SCARD_S_SUCCESS){
           LogFilter2("SendAPDU SCardTransmit successful\n",hsCard);
       }else{
LogFilter2("SendAPDU SCardTransmit.ERROR in transmit %ld, statuslength: %ld, pioRecvPci.dwProtocol: %ld, pioRecvPci.cbPciLength: %ld\n",hsCard,lReturn,dwStatusLength,pioRecvPci.dwProtocol,pioRecvPci.cbPciLength); --------------------------------->I always got an INSUFFICIENT_BUFFER ERROR
       }
   }else{
LogFilter2("sendAPDU. instancia: %ld fallo al tras reconectar con éxito\n",hsCard);
   }
   }


I´ve searched in the previous posts of this forum, I also tried to disconnect to the card using SCARD_RESET_CARD in order make easier to the next proccess to detect the reset state of the card, and then reconnect, but I don´t find a solution to this trouble. Someone has any idea??

Finally, I´ll throw some questions which I would like to have a response:

¿When I use SCardBeginTransaction and then SCardEndTransaction(... SCARD_LEAVE_CARD), pcsclite leaves the card in a way that any other process can do the same to access the card (SCardBeginTransaction and then SCardEndTransaction(... SCARD_LEAVE_CARD) ) and achieve a correct comunication?

¿Why I cannot get good results using SCARD_RESET_CARD in SCardEndTransaction in each instance, and then in the other using SCardReconnect?

¿Could I get a solution sharing the context between all the process which access to my smart card shared library?


Thanks a lot for your time.
Jesús el tuty.














_______________________________________________
Muscle mailing list
[email protected]
http://lists.drizzle.com/mailman/listinfo/muscle

Reply via email to