Add a comanda to run GSM auth algorithm.

Change-Id: I55d4cf5ad4d50c473ed4febb171cbc8854d1fa99
This commit is contained in:
Alexander Chemeris
2018-01-26 15:49:49 +09:00
parent e6d4faa6f5
commit 6d4a0a1a3e

View File

@@ -100,12 +100,26 @@ class SimCardCommands(object):
r = self.select_file(ef)
return int(r[-1][4:8], 16) // int(r[-1][28:30], 16)
def run_gsm(self, rand):
def run_gsm_raw(self, rand):
'''
A3/A8 algorithm in the SIM card using the given RAND.
This function returns a raw result tuple.
'''
if len(rand) != 32:
raise ValueError('Invalid rand')
self.select_file(['3f00', '7f20'])
return self._tp.send_apdu(self.cla_byte + '88000010' + rand)
def run_gsm(self, rand):
'''
A3/A8 algorithm in the SIM card using the given RAND.
This function returns a parsed ((SRES, Kc), sw) tuple.
'''
(res, sw) = self.run_gsm_raw(rand)
if sw != '9000':
return (res, sw)
return ((res[0:8], res[8:]), sw)
def reset_card(self):
return self._tp.reset_card()