Project

General

Profile

Actions

Feature #6265

closed

decode numeric SW in case of errors

Added by laforge 21 days ago. Updated 33 minutes ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
pySim-prog
Target version:
-
Start date:
11/20/2023
Due date:
% Done:

0%

Spec Reference:

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.

Actions #1

Updated by dexter 33 minutes 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.

Actions

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)