herlesupreeth / pysim

Pysim repository from Osmocom with added features
GNU General Public License v2.0
13 stars 3 forks source link

SW match failed! Expected 9000 and got 6982 #1

Open ReeturajBhuyan opened 11 months ago

ReeturajBhuyan commented 11 months ago

Hello,

I am trying to program a SIM Card using pySim. But I am getting this below error pySim.exceptions.SwMatchError: SW match failed! Expected 9000 and got 6982

I guess this error basically means "Security condition not satisfied.” I am passing the below parameters in the prog command. IMSI 234015555020000 MSISDN 12800520000 mcc 234 mnc 015 AMDPIN ADM11111

./pySim-prog.py -p 0 -t sysmoUSIM-SJS1 --mcc=234 --mnc=015 --iccid=89010020000005348007 --imsi=234015555020000 --msisdn=+12800520000 -a ADM11111

Is there any other parameter that needs to be added or mandatory which is not included.

herlesupreeth commented 11 months ago

I believe your ADM pin is wrong. It should be only digits. Please check the ADM1 pin provided to you by sysmocom

ReeturajBhuyan commented 11 months ago

Hi We received this ADM pin. We tried using verify_adm using this pin and was successful. For testing I entered an incorrect/different pin and it responded with 6983 and said 1 retries left.

herlesupreeth commented 11 months ago

Hmm, so you are saying that the SIM ADMI1 key is ADM11111 ??

Also, can you post the full error you get when you attempt to program using pySIM??

ReeturajBhuyan commented 11 months ago

Yes we received the ADM pin as ADM11111. We verified the same using verify_adm pySIM-shell (MF)> pySIM-shell (MF)> verify_adm ADM11111 pySIM-shell (MF)> pySIM-shell (MF)>

I tried with a random ADM just to check. But got an 6983 "Authentication Method Blocked"

pySIM-shell (MF)> verify_adm 88888888 Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/cmd2/cmd2.py", line 2399, in onecmd_plus_hooks stop = self.onecmd(statement, add_to_history=add_to_history) File "/usr/local/lib/python3.10/dist-packages/cmd2/cmd2.py", line 2852, in onecmd stop = func(statement) File "/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim/pySim-shell.py", line 787, in do_verify_adm self._cmd.card._scc.verify_chv(self._cmd.card._adm_chv_num, h2b(pin_adm)) File "/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim/pySim/commands.py", line 523, in verify_chv self._chv_process_sw('verify', chv_no, code, sw) File "/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim/pySim/commands.py", line 511, in _chv_process_sw raise SwMatchError(sw, '9000') pySim.exceptions.SwMatchError: SW match failed! Expected 9000 and got 6983. EXCEPTION of type 'SwMatchError' occurred with message: SW match failed! Expected 9000 and got 6983.

We then proceeded to program the SIM using the below commands and parameters but got 6982 error.

./pySim-prog.py -p 0 -t sysmoUSIM-SJS1 --mcc=234 --mnc=015 --iccid=89010020000005348007 --imsi=234015555020000 --msisdn=+12800520000 -a ADM11111

pySim.exceptions.SwMatchError: SW match failed! Expected 9000 and got 6982.

ReeturajBhuyan commented 11 months ago

root@reeturaj--ubuntu:/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim# ./pySim-prog.py -p 0 -t sysmoUSIM-SJS1 --mcc=234 --mnc=015 --iccid=89010020000005348007 --imsi=234015555020000 --msisdn=+12800520000 -a ADM11111 Using PC/SC reader interface Ready for Programming: Insert card now (or CTRL-C to cancel) Generated card parameters :

Name : Magic SMSP : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000 ICCID : 89010020000005348007 MCC/MNC : 234/015 IMSI : 234015555020000 Ki : 2e52e940b1040f91fbaf9b2b35d7810f OPC : 74b1de734d753c7a3b3f1b9cffb532ac ACC : None ADM1(hex): 41444d3131313131 OPMODE : None Programming ...

Card programming failed with an exception: ---------------------8<--------------------- Traceback (most recent call last): File "/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim/pySim/commands.py", line 223, in update_binary chunk_data, chunk_sw = self._tp.send_apdu_checksw(pdu) File "/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim/pySim/transport/init.py", line 213, in send_apdu_checksw raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter) pySim.exceptions.SwMatchError: SW match failed! Expected 9000 and got 6982.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim/./pySim-prog.py", line 824, in rc = process_card(opts, first, ch) File "/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim/./pySim-prog.py", line 774, in process_card card.program(cp) File "/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim/pySim/legacy/cards.py", line 929, in program data, sw = self._scc.update_binary('2fe2', enc_iccid(p['iccid'])) File "/home/reeturaj/SIM_CARD/pyscard-2.0.7/pysim/pySim/commands.py", line 225, in update_binary raise ValueError('%s, failed to write chunk (chunk_offset %d, chunk_len %d)' % ValueError: SW match failed! Expected 9000 and got 6982., failed to write chunk (chunk_offset 0, chunk_len 10) ---------------------8<---------------------

Programming failed: Remove card from reader

laf0rge commented 11 months ago

Any SIM PIN, including the ADM PIN is a strictly numeric value. This is true in general for all UICC/SIM/USIM cards. There is simply no way how to encode characters... -- Sent from a mobile device. Please excuse my brevity.

ReeturajBhuyan commented 11 months ago

I had received the below Secret codes. All are numeric except the ADM PIN. GPIN1, PUK1, LPIN1, PUK2, ADM1(Keyset 1)

Is there any other security parameter that needs to be passed while programing the Cards?

herlesupreeth commented 11 months ago

@ReeturajBhuyan As @laf0rge (Harald from Sysmocom) mentioned ADM PIN cannot be anything other than digits so I would suggest to re-check ADM1 key.

ReeturajBhuyan commented 11 months ago

Thank you so much @laf0rge @herlesupreeth for the support. Let me get the SIM Cards and the documentation provided revalidated.