From a670425088a7f62d2f57de588ae75c0c3092fc3a Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 8 Jan 2021 20:19:11 +0100 Subject: [PATCH] cards.py: SJS1 + SJA2: Implement + Expose verify_adm() method SJS1 and SJA2 card types don't use the generic verify_adm() method of the Card base class, so they must override it with their own methods. Only this way application code can call card.verify_adm() irrespective of the card type. Change-Id: I05f7f3280873f006310266867f04a9ce1b0a63af --- pySim/cards.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pySim/cards.py b/pySim/cards.py index 41dd1798..dd8fe8b1 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -849,12 +849,17 @@ class SysmoUSIMSJS1(UsimCard): return None return None - def program(self, p): - + def verify_adm(self, key): # authenticate as ADM using default key (written on the card..) - if not p['pin_adm']: + if not key: raise ValueError("Please provide a PIN-ADM as there is no default one") - self._scc.verify_chv(0x0A, h2b(p['pin_adm'])) + (res, sw) = self._scc.verify_chv(0x0A, key) + if sw != '9000': + raise RuntimeError('Failed to authenticate with ADM key %s'%(key)) + return sw + + def program(self, p): + self.verify_adm(h2b(p['pin_adm'])) # select MF r = self._scc.select_file(['3f00']) @@ -1244,11 +1249,17 @@ class SysmoISIMSJA2(UsimCard, IsimCard): return None return None - def program(self, p): + def verify_adm(self, key): # authenticate as ADM using default key (written on the card..) - if not p['pin_adm']: + if not key: raise ValueError("Please provide a PIN-ADM as there is no default one") - self._scc.verify_chv(0x0A, h2b(p['pin_adm'])) + (res, sw) = self._scc.verify_chv(0x0A, key) + if sw != '9000': + raise RuntimeError('Failed to authenticate with ADM key %s'%(key)) + return sw + + def program(self, p): + self.verify_adm(h2b(p['pin_adm'])) # This type of card does not allow to reprogram the ICCID. # Reprogramming the ICCID would mess up the card os software