Feature #6265
opendecode numeric SW in case of errors
0%
Description
We quite often get support requests from users of pySim-prog
who run into ADM key errors which don't get decoded properly and rather repor backtraces:
> Using PC/SC reader number 0 > Ready for Programming: Insert card now (or CTRL-C to cancel) > Autodetected card type: sysmoISIM-SJA2 > Generated card parameters : [...] > Programming ... > > Card programming failed with an exception: > ---------------------8<--------------------- > Traceback (most recent call last): > File "./pySim-prog.py", line 822, in <module> > rc = process_card(scc, opts, first, ch) > File "./pySim-prog.py", line 774, in process_card > card.program(cp) > File "/home/xxxxxx/pysim/pySim/legacy/cards.py", line 1335, in program > self.verify_adm(h2b(p['pin_adm'])) > File "/home/xxxxxx/pysim/pySim/legacy/cards.py", line 1331, in verify_adm > (res, sw) = self._scc.verify_chv(0x0A, key) > File "/home/xxxxxx/pysim/pySim/commands.py", line 587, in verify_chv > self._chv_process_sw('verify', chv_no, code, sw) > File "/home/xxxxxx/pysim/pySim/commands.py", line 575, in _chv_process_sw > raise SwMatchError(sw, '9000') > pySim.exceptions.SwMatchError: SW match failed! Expected 9000 and got 6983.
We should not print raw exceptions like this but properly decode the status word according to the tables we do alrady have in pySim and give the user a meaningful error message.
Updated by dexter 5 months ago
- Status changed from New to Resolved
As far as I can see we already something like this implemented for quite some time now. As it seems, the log output is from an older version of pySim.
To be sure I have reproduced the situation which is shown in the log:
$ ./mksim_sja2.sh Using PC/SC reader number 2 Ready for Programming: Insert card now (or CTRL-C to cancel) Generated card parameters : > Name : Magic > SMSP : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000 > ICCID : 8988211000000433188 > MCC/MNC : 001/01 > IMSI : 001010000000102 > Ki : AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA > OPC : BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB > ACC : None > ADM1(hex): 3731333635363933 > OPMODE : None Programming ... Card programming failed with an exception: ---------------------8<--------------------- Traceback (most recent call last): File "/home/owner/work/git_master/pysim/pySim-prog.py", line 822, in <module> rc = process_card(scc, opts, first, ch) File "/home/owner/work/git_master/pysim/pySim-prog.py", line 774, in process_card card.program(cp) File "/home/owner/work/git_master/pysim/pySim/legacy/cards.py", line 1335, in program self.verify_adm(h2b(p['pin_adm'])) File "/home/owner/work/git_master/pysim/pySim/legacy/cards.py", line 1331, in verify_adm (res, sw) = self._scc.verify_chv(0x0A, key) File "/home/owner/work/git_master/pysim/pySim/commands.py", line 587, in verify_chv self._chv_process_sw('verify', chv_no, code, sw) File "/home/owner/work/git_master/pysim/pySim/commands.py", line 573, in _chv_process_sw (op_name, chv_no, b2h(pin_code).upper(), int(sw[3]))) RuntimeError: Failed to verify chv_no 0x0A with code 0x3731333635363933, 2 tries left. ---------------------8<--------------------- Programming failed: Remove card from reader
I think we may close this ticket.
Updated by fixeria 5 months ago
- Status changed from Resolved to New
dexter wrote in #note-1:
As far as I can see we already something like this implemented for quite some time now. As it seems, the log output is from an older version of pySim.
You're judging by a specific case in which the Status Word would be '63Cx'. Looking more carefully at the source code:
570 def _chv_process_sw(self, op_name: str, chv_no: int, pin_code: Hexstr, sw: SwHexstr):
571 if sw_match(sw, '63cx'):
572 raise RuntimeError('Failed to %s chv_no 0x%02X with code 0x%s, %i tries left.' %
573 (op_name, chv_no, b2h(pin_code).upper(), int(sw[3])))
574 elif (sw != '9000'):
575 raise SwMatchError(sw, '9000')
I can see it's still possible that one would get an error like in the ticket description if the status word ('6983' for instance) does not match '63Cx'.
The line numbers in the ticket description match the current code, see: https://cgit.osmocom.org/pysim/tree/pySim/commands.py#n575.
Also, I would guess this is not only about CHV errors, but also applies to other scenarios in which SW mismatch can occur?