From 6dd6f3e12ca1109bcc0de60aa273594dda7c7510 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 22 Oct 2023 10:28:18 +0200 Subject: [PATCH] prevent SimCardCommands.select_adf_by_aid bypassing lchan Now that pySim-shell is aware of logical channels and issues almost all of its APDUs on the currently selected channel, we must also make sure that ADF selection by AID (implemented by the CardBase class) issues the SELECT on the respective logical channel. Before this patch, SELECT ADF by AID would always be issued on the primary logical channel (0), irrespective of the currently active RuntimeLchan. Change-Id: Idf05c297e6a2e24ca539408b8912e348c0782bb4 Related: OS#6230 --- pySim/cards.py | 8 +++++--- pySim/runtime.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pySim/cards.py b/pySim/cards.py index 84f53e15..45736162 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -146,8 +146,10 @@ class UiccCardBase(SimCardBase): return True return False - def select_adf_by_aid(self, adf: str = "usim") -> Tuple[Optional[Hexstr], Optional[SwHexstr]]: + def select_adf_by_aid(self, adf: str = "usim", scc: Optional[SimCardCommands] = None) -> Tuple[Optional[Hexstr], Optional[SwHexstr]]: """Select ADF.U/ISIM in the Card using its full AID""" + # caller may pass a custom scc; we fall back to default + scc = scc or self._scc if is_hex(adf): aid = adf else: @@ -155,10 +157,10 @@ class UiccCardBase(SimCardBase): if aid: aid_full = self._complete_aid(aid) if aid_full: - return self._scc.select_adf(aid_full) + return scc.select_adf(aid_full) else: # If we cannot get the full AID, try with short AID - return self._scc.select_adf(aid) + return scc.select_adf(aid) return (None, None) def card_detect(scc: SimCardCommands) -> Optional[CardBase]: diff --git a/pySim/runtime.py b/pySim/runtime.py index 27c2ef1f..a54a1b63 100644 --- a/pySim/runtime.py +++ b/pySim/runtime.py @@ -299,7 +299,7 @@ class RuntimeLchan: for p in inter_path: try: if isinstance(p, CardADF): - (data, sw) = self.rs.card.select_adf_by_aid(p.aid) + (data, sw) = self.rs.card.select_adf_by_aid(p.aid, scc=self.scc) self.selected_adf = p else: (data, sw) = self.scc.select_file(p.fid) @@ -343,7 +343,7 @@ class RuntimeLchan: f = sels[name] try: if isinstance(f, CardADF): - (data, sw) = self.rs.card.select_adf_by_aid(f.aid) + (data, sw) = self.rs.card.select_adf_by_aid(f.aid, scc=self.scc) else: (data, sw) = self.scc.select_file(f.fid) self.selected_file = f