dexter has uploaded this change for review.
pysim/pcsc: do not use getProtocol for protocol selection
The documentation of the getProtocol provided by pyscard says:
"Return bit mask for the protocol of connection, or None if no
protocol set. The return value is a bit mask of
CardConnection.T0_protocol, CardConnection.T1_protocol,
CardConnection.RAW_protocol, CardConnection.T15_protocol"
This suggests that the purpose of getProtocol is not to determine
which protocols are supported. Its purpose is to determine which
protocol is currently selected (either through auto selection or
through the explicit selection made by the API user). This means
we are using getProtocol wrong.
So far this was no problem, since the auto-selected protocol
should be a supported protocol anyway. However, the automatic
protocol selection may not always return a correct result (see
bug report from THD-siegfried [1]).
Let's not trust the automatic protocol selection. Instead let's
parse the ATR and make the decision based on the TD1/TD2 bytes).
[1] https://osmocom.org/issues/6952
Related: OS#6952
Change-Id: Ib119948aa68c430e42ac84daec8b9bd542db7963
---
M pySim/transport/pcsc.py
1 file changed, 5 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/75/42475/1
diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py
index c92a3ba..1c1b5b2 100644
--- a/pySim/transport/pcsc.py
+++ b/pySim/transport/pcsc.py
@@ -26,6 +26,7 @@
from smartcard.Exceptions import NoCardException, CardRequestTimeoutException, CardConnectionException
from smartcard.System import readers
from smartcard.ExclusiveConnectCardConnection import ExclusiveConnectCardConnection
+from smartcard.ATR import ATR
from osmocom.utils import h2i, i2h, Hexstr
@@ -85,12 +86,12 @@
# Make card connection and select a suitable communication protocol
self._con.connect()
- supported_protocols = self._con.getProtocol();
+ atr = ATR(self._con.getATR())
self.disconnect()
- if (supported_protocols & CardConnection.T0_protocol):
- protocol = CardConnection.T0_protocol
+ if atr.isT0Supported():
+ protocol = CardConnection.T0_protocol
self.set_tpdu_format(0)
- elif (supported_protocols & CardConnection.T1_protocol):
+ elif atr.isT1Supported():
protocol = CardConnection.T1_protocol
self.set_tpdu_format(1)
else:
To view, visit change 42475. To unsubscribe, or for help writing mail filters, visit settings.