3 Commits

Author SHA1 Message Date
Vadim Yanitskiy
da2fa83256 pySim-shell.py: add a command for RUN GSM ALGORITHM
Change-Id: Id7876d83d018aca79253784411d3a9d54a249a0a
2022-04-22 15:54:00 +03:00
Vadim Yanitskiy
6865819859 SimCardCommands.run_gsm(): use send_apdu_checksw()
Change-Id: Ib713cf8154a3aba72bc5776a8d99ec47631ade28
2022-04-22 15:54:00 +03:00
Vadim Yanitskiy
a576764c5e fix SimCardCommands.run_gsm(): always use CLA=0xa0
Depending on the card type (SIM or USIM/ISUM), self.cla_byte may
be either 0xa0 or 0x00.  Sending RUN GSM ALGORITHM with CLA=0x00
fails with SW=6985 (Command not allowed), so let's make sure
that we always use CLA=0xa0 regardless of the card type.

Change-Id: Ia0abba136dbd4cdea8dbbc3c4d6abe12c2863680
2022-04-22 15:54:00 +03:00
2 changed files with 11 additions and 1 deletions

View File

@@ -866,6 +866,16 @@ class Iso7816Commands(CommandSet):
self._cmd.poutput(
'Negotiated Duration: %u secs, Token: %s, SW: %s' % (duration, token, sw))
run_gsm_algo_parser = argparse.ArgumentParser()
run_gsm_algo_parser.add_argument('rand', type=str, help='RAND value')
# not ISO7816-4 but TS 102 221
@cmd2.with_argparser(run_gsm_algo_parser)
def do_run_gsm_algo(self, opts):
(data, sw) = self._cmd.card._scc.run_gsm(opts.rand)
self._cmd.poutput('SRES: %s' % data[:8])
self._cmd.poutput('Kc: %s' % data[8:])
option_parser = argparse.ArgumentParser(prog='pySim-shell', description='interactive SIM card shell',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

View File

@@ -402,7 +402,7 @@ class SimCardCommands(object):
if len(rand) != 32:
raise ValueError('Invalid rand')
self.select_path(['3f00', '7f20'])
return self._tp.send_apdu(self.cla_byte + '88000010' + rand)
return self._tp.send_apdu_checksw('a0' + '88000010' + rand, sw='9000')
def authenticate(self, rand: str, autn: str, context='3g'):
"""Execute AUTHENTICATE (USIM/ISIM).