Change in pysim[master]: fileystem: fix ADF selection

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Fri Apr 2 14:33:24 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/23536 )

Change subject: fileystem: fix ADF selection
......................................................................

fileystem: fix ADF selection

When the ADF is selected, then this is done by the AID. At the moment
only the first 7 bytes of the AID are used to select the ADF.
sysmo-isim-sja2 tolerates this, but sysmo-usim-sjs1 does not. The Cards
class already has methods to deal with this problem. The method
select_adf_by_aid takes an ADF name and completes the AID from an
internal list. This can be extended to support partial hexadecimal AIDs
as well.

Change-Id: If99b143ae5ff42a889c52e8023084692e709e1b1
Related: OS#4963
---
M pySim-read.py
M pySim/cards.py
M pySim/filesystem.py
3 files changed, 26 insertions(+), 21 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/pySim-read.py b/pySim-read.py
index 7906685..638bd4b 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -251,7 +251,8 @@
 
 	# Check whether we have th AID of USIM, if so select it by its AID
 	# EF.UST - File Id in ADF USIM : 6f38
-	if '9000' == card.select_adf_by_aid():
+	data, sw = card.select_adf_by_aid(adf="usim")
+	if sw == '9000':
 		# Select USIM profile
 		usim_card = UsimCard(scc)
 
@@ -300,7 +301,8 @@
 			print("ePDGSelection: Can't read file -- " + str(e))
 
 	# Select ISIM application by its AID
-	if '9000' == card.select_adf_by_aid(adf="isim"):
+	data, sw = card.select_adf_by_aid(adf="isim")
+	if sw == '9000':
 		# Select USIM profile
 		isim_card = IsimCard(scc)
 
@@ -352,7 +354,8 @@
 
 	# Check whether we have th AID of ISIM, if so select it by its AID
 	# EF.IST - File Id in ADF ISIM : 6f07
-	if '9000' == card.select_adf_by_aid(adf="isim"):
+	data, sw = card.select_adf_by_aid(adf="isim")
+	if sw == '9000':
 		# EF.IST
 		(res, sw) = card.read_binary('6f07')
 		if sw == '9000':
diff --git a/pySim/cards.py b/pySim/cards.py
index 857d0b6..5eb2884 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -224,21 +224,21 @@
 
 	# Select ADF.U/ISIM in the Card using its full AID
 	def select_adf_by_aid(self, adf="usim"):
-		# Check for valid ADF name
-		if adf not in ["usim", "isim"]:
-			return None
-
-		# First (known) halves of the U/ISIM AID
-		aid_map = {}
-		aid_map["usim"] = "a0000000871002"
-		aid_map["isim"] = "a0000000871004"
-
-		for aid in self._aids:
-			if aid_map[adf] in aid:
-				(res, sw) = self._scc.select_adf(aid)
-				return sw
-
-		return None
+		# Find full AID by partial AID:
+		if is_hex(adf):
+			for aid in self._aids:
+				if len(aid) >= len(adf) and adf == aid[0:len(adf)]:
+					return self._scc.select_adf(aid)
+		# Find full AID by application name:
+		elif adf in ["usim", "isim"]:
+			# First (known) halves of the U/ISIM AID
+			aid_map = {}
+			aid_map["usim"] = "a0000000871002"
+			aid_map["isim"] = "a0000000871004"
+			for aid in self._aids:
+				if aid_map[adf] in aid:
+					return self._scc.select_adf(aid)
+		return (None, None)
 
 	# Erase the contents of a file
 	def erase_binary(self, ef):
@@ -1335,7 +1335,8 @@
 			self._scc.update_binary('6f20', p['opc'], 17)
 
 		# update EF-USIM_AUTH_KEY in ADF.ISIM
-		if '9000' == self.select_adf_by_aid(adf="isim"):
+		data, sw = self.select_adf_by_aid(adf="isim")
+		if sw == '9000':
 			if p.get('ki'):
 				self._scc.update_binary('af20', p['ki'], 1)
 			if p.get('opc'):
@@ -1382,7 +1383,8 @@
 				if sw != '9000':
 					print("Programming IMPU failed with code %s"%sw)
 
-		if '9000' == self.select_adf_by_aid():
+		data, sw = self.select_adf_by_aid(adf="usim")
+		if sw == '9000':
 			# update EF-USIM_AUTH_KEY in ADF.USIM
 			if p.get('ki'):
 				self._scc.update_binary('af20', p['ki'], 1)
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 9f3b221..cd08699 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -665,7 +665,7 @@
             f = sels[name]
             try:
                 if isinstance(f, CardADF):
-                    (data, sw) = self.card._scc.select_adf(f.aid)
+                    (data, sw) = self.card.select_adf_by_aid(f.aid)
                 else:
                     (data, sw) = self.card._scc.select_file(f.fid)
                 self.selected_file = f

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: If99b143ae5ff42a889c52e8023084692e709e1b1
Gerrit-Change-Number: 23536
Gerrit-PatchSet: 5
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210402/023e0df9/attachment.htm>


More information about the gerrit-log mailing list