LudovicRousseau / pyscard

pyscard smartcard library for python
http://pyscard.sourceforge.net/
GNU Lesser General Public License v2.1
396 stars 113 forks source link

OS-dependent behaviour: #155

Closed Bustel closed 1 year ago

Bustel commented 1 year ago

Your system information

Please describe your issue in as much detail as possible:

I have a small CardMonitor application for Mifare Desfire cards that I want to port from Ubuntu to Windows. However I observe a strange behaviour for the Desfire EV1 cards we use here: When I run my script under Windows the card responds to my payloads with 0x6E00 "Class not supported".

Eg. Select Application 0x654441

90 5A 00 00 03 65 44 41 00 < [] 6E 00

I am not sure if this is a pyscard issue because it does not apply to all cards just to a particular batch. But given that it works perfectly fine under Ubuntu I am lost. Is there anything in the communication during the connect() that differs between OSs?

LudovicRousseau commented 1 year ago

I imagine you use the same reader under Ubuntu and Windows. Right?

I guess the Windows driver is doing something extra the Ubuntu driver does not. PySCard is not involved here.

What reader driver do you use on Ubuntu? libccid?

Bustel commented 1 year ago

I use the same Identiv uTrust 3700 F Reader for both Linux and Windows. Is it possible that the Windows driver does something based on the ATR bytes? The cards that don't work have more information in them:

ATR_BROKEN: 3B 89 80 01 4A 43 4F 50 32 34 32 52 33 4B ATR_WORKS: 3B 81 80 01 80 80

But I think you can close this issue since it's indeed not pyscard.

LudovicRousseau commented 1 year ago

My question was not about the reader but the reader driver.

It looks like your problematic cards are from Feitian https://smartcard-atr.apdu.fr/parse?ATR=3B8980014A434F5032343252334B While the working cards are DESFire https://smartcard-atr.apdu.fr/parse?ATR=3B8180018080

You should contact the smart card manufacturer and/or the Windows reader driver provider. Or try on the pcsclite-muscle mailing list https://ludovicrousseau.blogspot.com/2020/11/how-to-get-smart-card-support.html

I can't help.

Bustel commented 1 year ago

I figured it out. It has indeed nothing to do with pyscard but I will leave this here in case somebody runs into a similar problem:

The cards in question were recognized by some other Windows specific process which sends APDUs in a different format which causes the cards to switch communication modes. I noticed this while trying (and failing) to connect with mode=SCARD_SHARE_EXLUSIVE.

My solution was to find the competing process using ProcessExplorer and searching for Winscard.dll. It was some svchost.exe. Apparently something related to the Certificate Propagation Service. After I killed it everything works as expected.