Hello William,

Le 26/05/2011 20:38, Viktor TARASOV a écrit :
I'm also actually looking into this logs and it seems strange the after 
releasing of context it starts to read the cardcf .
In any case the 'zero' cardcf can be disturbing for baseCSP.

Another 'feature' is when the 'HANDLES CHANGED' event happens, the 
disassociate/associate card procedures pair called,
and 'cardcf' content is cleaned but not re-initialized. That's where from there 
is 'zero' content.

Could you please try the following test patch .
With this patch the cardcf content is deduced from the 'last_update' attribute 
of the token info data,
and not from the minidriver internal data. So that we'll avoid a 'zero' content 
of cardcf.

Also the initialization of  'cardcf' content is moved from CardAcquireContext() 
to the associate_card() procedure .

Kind regards,
Viktor.

Index: src/minidriver/minidriver.c
===================================================================
--- src/minidriver/minidriver.c (révision 5514)
+++ src/minidriver/minidriver.c (copie de travail)
@@ -95,7 +95,7 @@
 {
        va_list arg;
        VENDOR_SPECIFIC *vs;
-/* #define CARDMOD_LOW_LEVEL_DEBUG 1 */
+#define CARDMOD_LOW_LEVEL_DEBUG 1 
 #ifdef CARDMOD_LOW_LEVEL_DEBUG
 /* Use a simplied log to get all messages including messages
  * before opensc is loaded. The file must be modifiable by all
@@ -378,6 +378,35 @@
 }
 
 
+static void set_cardcf(PCARD_CACHE_FILE_FORMAT pcardcf, char *last_update)
+{
+       WORD cf = 0, ff = 0;
+
+       if (!pcardcf)
+               return;
+
+       if (!last_update || strlen(last_update) < 4*sizeof(WORD))   {
+               cf = rand()%0x7FFF;
+               ff = rand()%0x7FFF;
+       }
+       else   {
+               int ii;
+
+               if (strlen(last_update) > 4*sizeof(WORD))
+                       last_update += strlen(last_update) - 4*sizeof(WORD) - 1;
+
+               for (ii=0; ii < 2*sizeof(WORD); ii++)   {
+                       cf += (WORD)(*(last_update + ii)&0x0F) << (4*ii);
+                       ff += (WORD)(*(last_update + ii + 2*sizeof(WORD))&0x0F) 
<< (4*ii);
+               }
+       }
+
+       pcardcf->wContainersFreshness = cf;
+       pcardcf->wFilesFreshness = ff;
+       pcardcf->bVersion = CARD_CACHE_FILE_CURRENT_VERSION;
+}
+
+
 DWORD WINAPI CardDeleteContext(__inout PCARD_DATA  pCardData)
 {
        VENDOR_SPECIFIC *vs = NULL;
@@ -787,9 +816,7 @@
                        *pcbData = sizeof(vs->cardFiles.file_cardcf);
                        *ppbData = pCardData->pfnCspAlloc(*pcbData);
                        if(!*ppbData)
-                       {
                                return SCARD_E_NO_MEMORY;
-                       }
 
                        memcpy(*ppbData, &(vs->cardFiles.file_cardcf), 
*pcbData);
 
@@ -1887,17 +1914,6 @@
 
        logprintf(pCardData, 1, "OpenSC init done.\n");
 
-       if(sc_get_challenge(vs->p15card->card, challenge, sizeof(challenge)))
-       {
-               vs->cardFiles.file_cardcf.wContainersFreshness = rand()%30000;
-               vs->cardFiles.file_cardcf.wFilesFreshness = rand()%30000;
-       }
-       else
-       {
-               vs->cardFiles.file_cardcf.wContainersFreshness = 
challenge[0]*256+challenge[1];
-               vs->cardFiles.file_cardcf.wFilesFreshness = 
challenge[3]*256+challenge[4];
-       }
-
        if (suppliedVersion > 4) {
                pCardData->pfnCardDeriveKey = CardDeriveKey;
                pCardData->pfnCardDestroyDHAgreement = CardDestroyDHAgreement;
@@ -1964,11 +1980,14 @@
                }
        }
 
-       if(vs->card == NULL || vs->p15card == NULL)
-       {
+       if(vs->card == NULL || vs->p15card == NULL)   {
                logprintf(pCardData, 0, "Card unknow.\n");
                return SCARD_E_UNKNOWN_CARD;
        }
+       else if (vs->p15card->tokeninfo == NULL)   {
+               logprintf(pCardData, 0, "Invalid PKCS#15 card: no token info 
data\n");
+               return SCARD_E_UNKNOWN_CARD;
+       }
 
        /*
         * We want a 16 byte unique serial number
@@ -1980,7 +1999,7 @@
         * TODO needs to be looked at closer
         */
 
-       if (vs->p15card->tokeninfo && vs->p15card->tokeninfo->serial_number) {
+       if (vs->p15card->tokeninfo->serial_number) {
                size_t len1, len2;
                char * cserial;
 
@@ -1997,9 +2016,9 @@
                loghex(pCardData, 7, vs->cardFiles.file_cardid, 
sizeof(vs->cardFiles.file_cardid));
        }
 
+       set_cardcf(&(vs->cardFiles.file_cardcf), 
vs->p15card->tokeninfo->last_update);
 
-       r = sc_pkcs15_get_objects(vs->p15card, SC_PKCS15_TYPE_CERT_X509, \
-               vs->cert_objs, 32);
+       r = sc_pkcs15_get_objects(vs->p15card, SC_PKCS15_TYPE_CERT_X509, 
vs->cert_objs, 32);
        if (r < 0)
        {
                logprintf(pCardData, 0, "Certificate enumeration failed: %s\n", 
\
_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to