From fa617ac20d224fe65b84a44e0f1bb5e1a3535695 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Wed, 26 Feb 2020 22:33:08 +0700 Subject: [PATCH] transport/pcsc: explicitly specify T0 protocol From pyscard user's guide [1]: == Selecting the card communication protocol == By defaults, the connect() method of the CardConnection object will try to connect using either the T=0 or T=1 protocol. To force a connection protocol, you can pass the required protocol to the connect() method. This means that a PC/SC ifd handler may automatically choose T=1 as the highest protocol if the card indicates both in its ATR [2]. Since pySim only supports T=0, let's select it explicitly. [1] https://pyscard.sourceforge.io/user-guide.html [2] https://github.com/acshk/acsccid/issues/16#issuecomment-501101972 Change-Id: Ifed4574aab98a86c3ebbeb191f36a8282103e775 --- pySim/transport/pcsc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py index 7fa922ff..380c8fdd 100644 --- a/pySim/transport/pcsc.py +++ b/pySim/transport/pcsc.py @@ -22,6 +22,7 @@ # along with this program. If not, see . # +from smartcard.CardConnection import CardConnection from smartcard.CardRequest import CardRequest from smartcard.Exceptions import NoCardException, CardRequestTimeoutException from smartcard.System import readers @@ -52,7 +53,10 @@ class PcscSimLink(LinkBase): def connect(self): try: - self._con.connect() + # Explicitly select T=0 communication protocol + self._con.connect(CardConnection.T0_protocol) + except CardConnectionException: + raise ProtocolError() except NoCardException: raise NoCardError()