Le 11/08/2011 13:29, Ludovic Rousseau a écrit :
> 2011/8/11 Viktor Tarasov<viktor.tara...@gmail.com>:
>> Le 08/08/2011 16:31, Ludovic Rousseau a écrit :
>>> 2011/7/19 Viktor Tarasov<viktor.tara...@gmail.com>:
>>>> Le 18/07/2011 14:52, Ludovic Rousseau a écrit :
>>>>> 2011/7/10 Viktor Tarasov<viktor.tara...@gmail.com>:
>>>>>> Hi,
>>>>> Hello,
>>>>>
>>>>>> there is patch proposal to treat properly the 'detach token(reader)'
>>>>>> event
>>>>>> and to remove the slots associated to the removed token.
>>>>>>
>>>>>> Tested in Linux and windows.
>>>>>> 'SCardGetStatusChange' have different behavior in Linux and Windows.
>>>>>> Needs to be studied and validated for Mac.
>>>>>>
>>>>>>
>>>>>>
>>>>>> https://github.com/viktorTarasov/OpenSC/commit/62bda63bd66c4849c0ca4303a9682fb6f6bacd7d
>>>>>   /* When token is hot-unplugged:
>>>>>    * - in Linux (pcsc-lite)
>>>>>    * -- SCardGetStatusChange returns OK;
>>>>>    * -- current reader state is 'UNKNOWN';
>>>>>    * -- 'Refresh-attributes' returns 'SC_ERROR_READER_DETACHED'.
>>>>>    *
>>>>>    * - in Windows (WinSCard):
>>>>>    * -- SCardGetStatusChange failes with SCARD_E_NO_READERS_AVAILABLE;
>>>>>    * -- 'Refresh-attributes' returns 'SC_ERROR_NO_READERS_FOUND'.
>>>>>    *
>>>>>    * - FIXME: Mac?
>>>>>    */
>>>>>
>>>>> I just checked on Mac OS X 10.6.8 (Snow Leopard) and I have nearly the
>>>>> same result as on GNU/Linux.
>>>>> On GNU/Linux : new state is 14 =>      ['Changed', 'Unknown',
>>>>> 'Unavailable']
>>>>> On Mac OS X : new state is 6 =>      ['Changed', 'Unknown]
>>>>>
>>>>> On Windows, do you also get the error SCARD_E_NO_READERS_AVAILABLE
>>>>> when you use TWO readers in the SCardGetStatusChange() call?
>>>> I do not completely follow.
>>>>
>>>> SCardGetStatusChange is called by refresh_attributes(sc_reader_t
>>>> *reader).
>>>> In this context there is only one reader.
>>>>
>>>> When this reader is unplugged in Windows the SCardGetStatusChange returns
>>>> 8010002E -- SCARD_E_NO_READERS_AVAILABLE.
>>>> In Linux SCardGetStatusChange returns OK and properly sets a new reader
>>>> status.
>>>> Imho both have a reason.
>>> I can't reproduce the "problem" on my Windows XP using my Python sample.
>>>
>>> If SCardGetStatusChange() is called with a removed/unknown reader then
>>> Windows SCardGetStatusChange() returns with SCARD_E_UNKNOWN_READER. I
>>> just changed pcsc-lite in revision 5881 to also return
>>> SCARD_E_UNKNOWN_READER when called with unknown reader(s).
>>>
>>> If I unplug a reader while SCardGetStatusChange() is running I get
>>> SCARD_S_SUCCESS and the new reader state is ['Ignore', 'Changed',
>>> 'Unavailable']
>>>
>>> Viktor, are you using Windows XP? or a newer version?
>> I use WindowsXP SP2 in VM and pkcs11-tool from OpenSC to make the tests .
>> I will experiment with more debugs to get know the details of the calling
>> context .
> I used my Python sample test
> http://anonscm.debian.org/viewvc/pcsclite/trunk/PCSC/UnitaryTests/SCardGetStatusChange.py?view=markup
>
>> For you the 'normal' behavior of SCardGetStatusChange() is to return
>> SCARD_S_SUCCESS and appropriate reader status,
>> is it so?
> Yes. Unless the reader is unknown (has been removed) _before_
> SCardGetStatusChange() is called.


In the OpenSC context the detached reader/token is unknown before the 
SCardGetStatusChange() called.
In windows, XP or Vista, the ScardGetStatusChange called for unknown reader 
returns SCARD_E_NO_READERS_AVAILABLE.

The last revision of pcsc-lite, in such a case, returns the 
SCARD_E_UNKNOWN_READER, which seems to be more appropriate to the situation.


> > From your log opensc-debug.win32.detach-unique-token.log I interpret it as:
> - OpenSC gets a card removed event
> 2011-07-22 11:34:45.763 'Aktiv Rutoken ECP 0' before=0x00010122 now=0x0000000B
> 2011-07-22 11:34:45.763 card removed event
>
> - OpenSC calls SCardGetStatusChange() and get SCARD_E_NO_READERS_AVAILABLE
> 2011-07-22 11:34:45.950 [opensc-pkcs11]
> reader-pcsc.c:361:pcsc_detect_card_presence: called
> 2011-07-22 11:34:45.950 Aktiv Rutoken ECP 0 check
> 2011-07-22 11:34:45.950 Aktiv Rutoken ECP 0:SCardGetStatusChange
> failed: 0x8010002e
> 2011-07-22 11:34:45.950 [opensc-pkcs11]
> reader-pcsc.c:365:pcsc_detect_card_presence: returning with: -1101 (No
> readers found)
>
> Since this is a token, a card removed event is also a reader removed event.
> So it is normal to get an error from SCardGetStatusChange(). pcsc-lite
> will return SCARD_E_UNKNOWN_READER instead of
> SCARD_E_NO_READERS_AVAILABLE returned by Windows XP.
> Windows XP also returns SCARD_E_UNKNOWN_READER (with my sample). So I
> guess my Python sample does not do exactly what OpenSC is doing.


In you sample the SCardGetStatusChange is called _before_ the reader is 
detached (and 'detach' event is waited for on the timeout of 
ScardGetStatusChange).

To reproduce the ""problem"" and approach the OpenSC context you probably need 
to introduce 'time.sleep()' into your script before SCardGetStatusChange
and withdraw the token during it.

Also the SCardGetStatusChange has to be called on one reader, as it's the case 
of 'refresh_attributes' in OpenSC. So, without changes of your script, during 
your tests, your need to withdraw the unique token.


> I will do more testing and try to find in which cases Windows returns 
> SCARD_E_NO_READERS_AVAILABLE.

Do you think that the results of this investigation could influence the 
proposed solution for the actual bug in OpenSC ?

> By

Kind regards,
Viktor.

_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to