card: re-add capability to find USIM cards by ATR

de31d9f88b removes the ability to select
USIM cards by specifiying their ATR. This feature is needed to
properly distinguish symo-usim-sjs1 and sysmo-isim-sja2 from other
cards.
This commit is contained in:
Philipp Maier 2020-09-10 22:44:18 +02:00
parent fd95de36de
commit a767cec4d0
4 changed files with 11 additions and 7 deletions

View File

@ -35,6 +35,7 @@ import re
# smartcard python modules from pyscard
from smartcard.CardType import AnyCardType
from smartcard.CardType import ATRCardType
from smartcard.CardRequest import CardRequest
from smartcard.CardConnection import CardConnection
from smartcard.ATR import ATR
@ -141,7 +142,7 @@ class ISO7816(object):
0xAB : 'Security Attribute expanded',
}
def __init__(self, CLA=0x00):
def __init__(self, atr=None, CLA=0x00):
"""
connect smartcard and defines class CLA code for communication
uses "pyscard" library services
@ -149,6 +150,9 @@ class ISO7816(object):
creates self.CLA attribute with CLA code
and self.coms attribute with associated "apdu_stack" instance
"""
if (atr):
cardtype = ATRCardType(atr)
else:
cardtype = AnyCardType()
cardrequest = CardRequest(timeout=1, cardType=cardtype)
self.cardservice = cardrequest.waitforcard()

View File

@ -100,12 +100,12 @@ class SIM(ISO7816):
use self.dbg = 1 or more to print live debugging information
"""
def __init__(self):
def __init__(self, atr = None):
"""
initialize like an ISO7816-4 card with CLA=0xA0
can also be used for USIM working in SIM mode,
"""
ISO7816.__init__(self, CLA=0xA0)
ISO7816.__init__(self, atr, CLA=0xA0)
if self.dbg >= 2:
log(3, '(SIM.__init__) type definition: %s' % type(self))

View File

@ -177,7 +177,7 @@ class USIM(UICC):
use self.dbg = 1 or more to print live debugging information
"""
def __init__(self):
def __init__(self, atr = None):
"""
initializes like an ISO7816-4 card with CLA=0x00
and checks available AID (Application ID) read from EF_DIR
@ -185,7 +185,7 @@ class USIM(UICC):
initializes on the MF
"""
# initialize like a UICC
ISO7816.__init__(self, CLA=0x00)
ISO7816.__init__(self, atr, CLA=0x00)
self.AID = []
if self.dbg >= 2:

View File

@ -85,7 +85,7 @@ class Simcard():
# Constructor: Create a new simcard object
def __init__(self, cardtype = GSM_USIM, atr = None):
if cardtype == GSM_USIM:
self.card = USIM()
self.card = USIM(atr)
self.usim = True
# Detect ISIM / USIM applications