Project

General

Profile

Bug #4419

CardConnectionException: Failed to transmit with protocol T0. Transaction failed.

Added by fixeria 3 months ago. Updated 3 months ago.

Status:
Resolved
Priority:
High
Assignee:
Target version:
-
Start date:
02/27/2020
Due date:
% Done:

100%

Spec Reference:

Description

For some reason, pySim-prog.py fails to program a SIM card when using Python 3.

Using PC/SC reader (dev=0) interface
Ready for Programming: Insert card now (or CTRL-C to cancel)
Autodetected card type: sysmoUSIM-SJS1
Generated card parameters :
 > Name     : Osmocom
 > SMSP     : e1ffffffffffffffffffffffff068100095155f5ffffffffff000000
 > ICCID    : [REMOVED]
 > MCC/MNC  : 901/70
 > IMSI     : 901700000025647
 > Ki       : [REMOVED]
 > OPC      : [REMOVED]
 > ACC      : None
 > ADM1(hex): [REMOVED]
Programming ...

Card programming failed with an execption:
---------------------8<---------------------
Traceback (most recent call last):
  File "./pySim-prog.py", line 751, in <module>
    rc = process_card(opts, first, card_handler)
  File "./pySim-prog.py", line 689, in process_card
    card.program(cp)
  File "/home/fixeria/osmocom/pysim/pySim/cards.py", line 602, in program
    data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid']))
  File "/home/fixeria/osmocom/pysim/pySim/commands.py", line 128, in update_binary
    self.select_file(ef)
  File "/home/fixeria/osmocom/pysim/pySim/commands.py", line 106, in select_file
    data, sw = self._tp.send_apdu_checksw(self.cla_byte + "a4" + self.sel_ctrl + "02" + i)
  File "/home/fixeria/osmocom/pysim/pySim/transport/__init__.py", line 93, in send_apdu_checksw
    rv = self.send_apdu(pdu)
  File "/home/fixeria/osmocom/pysim/pySim/transport/__init__.py", line 68, in send_apdu
    data, sw = self.send_apdu_raw(pdu)
  File "/home/fixeria/osmocom/pysim/pySim/transport/pcsc.py", line 76, in send_apdu_raw
    data, sw1, sw2 = self._con.transmit(apdu, CardConnection.T0_protocol)
  File "/usr/lib/python3.8/site-packages/smartcard/CardConnectionDecorator.py", line 82, in transmit
    return self.component.transmit(bytes, protocol)
  File "/usr/lib/python3.8/site-packages/smartcard/CardConnection.py", line 146, in transmit
    data, sw1, sw2 = self.doTransmit(bytes, protocol)
  File "/usr/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardConnection.py", line 200, in doTransmit
    raise CardConnectionException(
smartcard.Exceptions.CardConnectionException: Failed to transmit with protocol T0. Transaction failed.
---------------------8<---------------------

At the same time, reading a SIM card works just fine. Switching back to Python 2 makes pySim-prog.py work again.

I grabbed debug output of pcscd using the following command:

$ sudo LIBCCID_ifdLogLevel=0x0007 pcscd -fd | tee /tmp/pcscd.log

Please seee attached files and the difference between them.

pcscd_py3.log pcscd_py3.log 39.9 KB fixeria, 02/26/2020 05:33 PM
pcscd_py2.log pcscd_py2.log 101 KB fixeria, 02/26/2020 05:33 PM
pcscd_py23.diff pcscd_py23.diff 72.4 KB fixeria, 02/26/2020 05:33 PM

History

#1 Updated by fixeria 3 months ago

More details:

  • Common card / reader details:
    • Card type: sysmoUSIM-SJS1
    • Reader: OMNIKEY AG 3121
  • My machine, Arch Linux:
    • Python versions: 2.7 vs 3.8
    • pyscard version: 1.9.9 [1]
  • Jenkins build slave [2] (also affected):
    • Python versions: 2.7 vs 3.5
    • pyscard version: 1.9.4

[1] https://www.archlinux.org/packages/community/x86_64/python-pyscard/
[2] https://jenkins.osmocom.org/jenkins/job/gerrit-pysim/338/a1=default,a2=default,a3=default,a4=default,label=simtester/console

#2 Updated by fixeria 3 months ago

Here is the difference:

@@ -545,855 +545,21 @@ winscard_svc.c:361:ContextThread() Received command: TRANSMIT from client 15
 readerfactory.c:848:RFReaderInfoById() RefReader() count was: 1
 winscard.c:1595:SCardTransmit() Send Protocol: T=0
 ifdhandler.c:1302:IFDHTransmitToICC() usb:076b/3022:libudev:0:/dev/bus/usb/001/002 (lun: 0)
-commands.c:1623:CmdXfrBlockAPDU_extended() T=0 (extended): 7 bytes
--> 000000 6F 07 00 00 00 00 1E 00 00 00 00 A4 00 04 02 2F E2 
-<- 000000 80 02 00 00 00 00 1E 00 00 00 61 20
+commands.c:1623:CmdXfrBlockAPDU_extended() T=0 (extended): 5 bytes
+-> 000000 6F 05 00 00 00 00 1E 00 00 00 00 A4 00 04 02 
+<- 000000 80 00 00 00 00 00 1E 40 FE 00 
+commands.c:1523:CCID_Receive Card absent or mute
+ifdwrapper.c:543:IFDTransmit() Card not transacted: 612
+winscard.c:1620:SCardTransmit() Card not transacted: 0x80100016

This APDU comes from pySim/commands.py, SimCardCommands.select_file().

#3 Updated by fixeria 3 months ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 100

https://gerrit.osmocom.org/c/pysim/+/17280 commands: Python 3 fix: properly distinguish str and list

#4 Updated by fixeria 3 months ago

  • Status changed from Feedback to Resolved

Merged.

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)