Change in pysim[master]: cards.py: SJS1 + SJA2: Implement + Expose verify_adm() method

laforge gerrit-no-reply at lists.osmocom.org
Tue Mar 2 06:36:03 UTC 2021


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/23168 )


Change subject: cards.py: SJS1 + SJA2: Implement + Expose verify_adm() method
......................................................................

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
---
M pySim/cards.py
1 file changed, 18 insertions(+), 7 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/68/23168/1

diff --git a/pySim/cards.py b/pySim/cards.py
index 41dd179..2d93713 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -849,12 +849,17 @@
 			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 @@
 			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._scc.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

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23168
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I05f7f3280873f006310266867f04a9ce1b0a63af
Gerrit-Change-Number: 23168
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210302/9d37db2f/attachment.htm>


More information about the gerrit-log mailing list