mitshell / card

Facilitates communications with telco smartcard (especially SIM and USIM)
http://michau.benoit.free.fr/
GNU General Public License v2.0
144 stars 56 forks source link

Allowing the user to select card reader #5

Closed domi007 closed 3 years ago

domi007 commented 4 years ago

It could be very useful in an environment with multiple cards connected to a single machine to be able to exactly specify the name of the reader to use instead of relying on possibly random selection. The change introduced keeps backward-compatibility via default empty parameters.

mitshell commented 4 years ago

Thanks for the PR Domi. Could you please provide me few examples of reader arguments ? Just for curiosity.

domi007 commented 4 years ago

Sure thing Benoit. The reader argument is the name of the reader, as reported by pcscd. This is widely used as a reference to each reader (instead of e.g. USB device ID or something else).

# pcsc_scan 
PC/SC device scanner
V 1.5.2 (c) 2001-2017, Ludovic Rousseau <ludovic.rousseau@free.fr>
Using reader plug'n play mechanism
Scanning present readers...
0: VMware Virtual USB CCID 00 00
1: VMware Virtual USB CCID 00 01

Example:

from card.USIM import *
from smartcard.System import readers

for r in readers():
  u = USIM(reader=str(r))
  print("IMSI:", u.get_imsi(), "(reader:", str(r), ")")

Output:

IMSI: XXX (reader: VMware Virtual USB CCID 00 00 )
IMSI: YYY (reader: VMware Virtual USB CCID 01 00 )
mitshell commented 3 years ago

Maybe it's coming late, but better late than never :) Commit https://github.com/mitshell/card/commit/f68ccd98386395eb2784a4b71f8ff4b3d03046b7 enables to pass a smartcard reader name in every class constructors: that should address your case !