From 6d4a0a1a3e9a1d9bcc5a978112bf34f11005dc16 Mon Sep 17 00:00:00 2001 From: Alexander Chemeris Date: Fri, 26 Jan 2018 15:49:49 +0900 Subject: Add a comanda to run GSM auth algorithm. Change-Id: I55d4cf5ad4d50c473ed4febb171cbc8854d1fa99 --- pySim/commands.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'pySim/commands.py') diff --git a/pySim/commands.py b/pySim/commands.py index eba915c..1a7584b 100644 --- a/pySim/commands.py +++ b/pySim/commands.py @@ -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() -- cgit v1.2.3