laforge has uploaded this change for review.

View Change

pySim.cards: Make file_exists() check for activated/deactivated

The Card.file_exists() method is only called by legacy pySim-{read,prog}
when it wants to determine if it can read/write a file. Therefore
it actually doesn't only want to know if the file exists, but also
if it's not deactivated.

Change-Id: I73bd1ab3780e475c96a10cd5dbdd45b829c67335
Closes: OS#6530
---
M pySim/cards.py
1 file changed, 8 insertions(+), 1 deletion(-)

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/78/37778/1
diff --git a/pySim/cards.py b/pySim/cards.py
index 802c921..65aef98 100644
--- a/pySim/cards.py
+++ b/pySim/cards.py
@@ -23,7 +23,7 @@
#

from typing import Optional, Tuple
-from pySim.ts_102_221 import EF_DIR
+from pySim.ts_102_221 import EF_DIR, CardProfileUICC
from pySim.ts_51_011 import DF_GSM

from pySim.utils import *
@@ -54,10 +54,17 @@
print("warning: erasing is not supported for specified card type!")

def file_exists(self, fid: Path) -> bool:
+ """Determine if the file exists (and is not deactivated)."""
res_arr = self._scc.try_select_path(fid)
for res in res_arr:
if res[1] != '9000':
return False
+ try:
+ d = CardProfileUICC.decode_select_response(res_arr[-1][0])
+ if d.get('life_cycle_status_integer', 'operational_activated') != 'operational_activated':
+ return False
+ except:
+ pass
return True

def read_aids(self) -> List[Hexstr]:

To view, visit change 37778. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I73bd1ab3780e475c96a10cd5dbdd45b829c67335
Gerrit-Change-Number: 37778
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>