diff --git a/cards/__init__.py b/cards/__init__.py index c477d87..31166c9 100644 --- a/cards/__init__.py +++ b/cards/__init__.py @@ -57,7 +57,7 @@ class Cardmultiplexer: MERGE_DICTS = ("APPLICATIONS", "COMMANDS", "STATUS_WORDS", "VENDORS") MERGE_DICTS_RECURSIVE = ("TLV_OBJECTS", "STATUS_MAP") - MERGE_LISTS = () + MERGE_LISTS = ("DRIVER_NAME", ) def __init__(self, classes, *args, **kwargs): """Creates a new Cardmultiplexer object. diff --git a/cards/cardos_card.py b/cards/cardos_card.py index 23276d8..b80d62b 100644 --- a/cards/cardos_card.py +++ b/cards/cardos_card.py @@ -3,7 +3,7 @@ from iso_7816_4_card import * import building_blocks class CardOS_Card(ISO_7816_4_Card,building_blocks.Card_with_ls): - DRIVER_NAME = "CardOS" + DRIVER_NAME = ["CardOS"] ATRS = [ ("3bf2180002c10a31fe58c80874", None), diff --git a/cards/cyberflex_card.py b/cards/cyberflex_card.py index 25c83e0..a7ac496 100644 --- a/cards/cyberflex_card.py +++ b/cards/cyberflex_card.py @@ -20,7 +20,7 @@ class Cyberflex_Card(Java_Card): APDU_EXTERNAL_AUTHENTICATE = C_APDU('\x84\x82\x00\x00') APDU_GET_STATUS = C_APDU('\x84\xF2\x00\x00\x02\x4f\x00') APDU_DELETE = C_APDU('\x84\xe4\x00\x00') - DRIVER_NAME = "Cyberflex" + DRIVER_NAME = ["Cyberflex"] ATRS = [ ## Cyberflex Access 32k v2 ??? @@ -293,7 +293,7 @@ class Cyberflex_Card(Java_Card): SECURE_CHANNEL_MAC: " [MAC]", SECURE_CHANNEL_MACENC: " [MAC+enc]"} def get_prompt(self): - return "(%s)%s" % (self.DRIVER_NAME, + return "(%s)%s" % (self.get_driver_name(), Cyberflex_Card._secname[self.secure_channel_state]) diff --git a/cards/generic_application.py b/cards/generic_application.py index 5b663b4..599636a 100644 --- a/cards/generic_application.py +++ b/cards/generic_application.py @@ -26,7 +26,7 @@ class Application: continue if possible_class.can_handle_aid(card, aid): classes_to_load.append(possible_class) - print ".oO(Loading application '%s')" % possible_class.DRIVER_NAME + print ".oO(Loading application '%s')" % ", ".join(possible_class.DRIVER_NAME) card.add_classes(classes_to_load) load_applications = staticmethod(load_applications) diff --git a/cards/generic_card.py b/cards/generic_card.py index d3f454d..a692aa3 100644 --- a/cards/generic_card.py +++ b/cards/generic_card.py @@ -9,8 +9,9 @@ PURPOSE_SUCCESS = 1 # Command executed successful PURPOSE_RETRY = 2 # Command executed successful but needs retry with correct length PURPOSE_SM_OK = 3 # Command not executed successful or with warnings, but response still contains SM objects +_GENERIC_NAME = "Generic" class Card: - DRIVER_NAME = "Generic" + DRIVER_NAME = [_GENERIC_NAME] APDU_GET_RESPONSE = C_APDU(ins=0xc0) APDU_VERIFY_PIN = C_APDU(ins=0x20) PURPOSE_SUCCESS, PURPOSE_RETRY, PURPOSE_SM_OK = PURPOSE_SUCCESS, PURPOSE_RETRY, PURPOSE_SM_OK @@ -248,7 +249,7 @@ class Card: can_handle = classmethod(can_handle) def get_prompt(self): - return "(%s)" % self.DRIVER_NAME + return "(%s)" % self.get_driver_name() def match_statusword(swlist, sw): """Try to find sw in swlist. @@ -290,6 +291,13 @@ class Card: def get_protocol(self): return ((self.card.status()["Protocol"] == pycsc.SCARD_PROTOCOL_T0) and (0,) or (1,))[0] + def get_driver_name(self): + if len(self.DRIVER_NAME) > 1: + names = [e for e in self.DRIVER_NAME if e != _GENERIC_NAME] + else: + names = self.DRIVER_NAME + return ", ".join(names) + def close_card(self): "Disconnect from a card" del self.card # FIXME: anything else to do? diff --git a/cards/gsm_card.py b/cards/gsm_card.py index 20a81ca..e3243a6 100644 --- a/cards/gsm_card.py +++ b/cards/gsm_card.py @@ -2,7 +2,7 @@ import utils from generic_card import * class GSM_Card(Card): - DRIVER_NAME = "GSM" + DRIVER_NAME = ["GSM"] APDU_GET_RESPONSE = C_APDU("\xa0\xC0\x00\x00") STATUS_MAP = { PURPOSE_RETRY: ("9F??", ) diff --git a/cards/iso_7816_4_card.py b/cards/iso_7816_4_card.py index bb86001..30cb6bc 100644 --- a/cards/iso_7816_4_card.py +++ b/cards/iso_7816_4_card.py @@ -7,7 +7,7 @@ class ISO_7816_4_Card(Card): APDU_SELECT_FILE = C_APDU(ins=0xa4, le=0) APDU_READ_BINARY = C_APDU(ins=0xb0,le=0) APDU_READ_RECORD = C_APDU(ins=0xb2,le=0) - DRIVER_NAME = "ISO 7816-4" + DRIVER_NAME = ["ISO 7816-4"] FID_MF = "\x3f\x00" SELECT_P2 = 0x0 diff --git a/cards/java_card.py b/cards/java_card.py index bcc4eef..1a3fb89 100644 --- a/cards/java_card.py +++ b/cards/java_card.py @@ -3,7 +3,7 @@ from generic_card import * from utils import C_APDU class Java_Card(Card): - DRIVER_NAME = "Generic Java" + DRIVER_NAME = ["Generic Java"] APPLICATIONS = { "\xa0\x00\x00\x00\x01\x01": ("muscle", "MUSCLE applet") } diff --git a/cards/mtcos_card.py b/cards/mtcos_card.py index 34cc755..9e78f30 100644 --- a/cards/mtcos_card.py +++ b/cards/mtcos_card.py @@ -3,7 +3,7 @@ from iso_7816_4_card import * import building_blocks class MTCOS_Card(ISO_7816_4_Card,building_blocks.Card_with_80_aa): - DRIVER_NAME = "MTCOS" + DRIVER_NAME = ["MTCOS"] ATRS = [ # This is the correct ATR according to PC/SC v.2 part 3 diff --git a/cards/passport_application.py b/cards/passport_application.py index 1ff33a3..6d9dc23 100644 --- a/cards/passport_application.py +++ b/cards/passport_application.py @@ -76,7 +76,7 @@ class Passport_Security_Environment(TCOS_Security_Environment): return Passport_Application._mac(self.card.KSmac, data, self.card.ssc, dopad=False) class Passport_Application(Application): - DRIVER_NAME = "Passport" + DRIVER_NAME = ["Passport"] APDU_GET_RANDOM = C_APDU(CLA=0, INS=0x84, Le=0x08) APDU_MUTUAL_AUTHENTICATE = C_APDU(CLA=0, INS=0x82, Le=0x28) APDU_SELECT_FILE = C_APDU(INS=0xa4) @@ -230,7 +230,7 @@ class Passport_Application(Application): _make_random = staticmethod(_make_random) def get_prompt(self): - return "(%s)%s" % (self.DRIVER_NAME, self.se and "[SM]" or "") + return "(%s)%s" % (self.get_driver_name(), self.se and "[SM]" or "") def check_sw(self, sw, purpose = None): if purpose is not Card.PURPOSE_SM_OK: diff --git a/cards/postcard_card.py b/cards/postcard_card.py index aece599..7a1e917 100644 --- a/cards/postcard_card.py +++ b/cards/postcard_card.py @@ -2,7 +2,7 @@ import utils, re, sys, getpass, struct from iso_7816_4_card import * class Postcard_Card(ISO_7816_4_Card): - DRIVER_NAME = "Postcard" + DRIVER_NAME = ["Postcard"] CLA = 0xbc APDU_GET_RESPONSE = C_APDU(cla=CLA,ins=0xc0) APDU_SELECT_FILE = C_APDU(cla=CLA,ins=0xa4) diff --git a/cards/seccos_card.py b/cards/seccos_card.py index b508f1d..389c250 100644 --- a/cards/seccos_card.py +++ b/cards/seccos_card.py @@ -2,7 +2,7 @@ import utils from iso_7816_4_card import * class SECCOS_Card(ISO_7816_4_Card): - DRIVER_NAME = "SECCOS" + DRIVER_NAME = ["SECCOS"] SELECT_P2 = 0x04 ATRS = [ diff --git a/cards/starcos_card.py b/cards/starcos_card.py index f1e7e0e..aacf65d 100644 --- a/cards/starcos_card.py +++ b/cards/starcos_card.py @@ -2,7 +2,7 @@ import utils from iso_7816_4_card import * class Starcos_Card(ISO_7816_4_Card): - DRIVER_NAME = "Starcos" + DRIVER_NAME = ["Starcos"] APDU_READ_BINARY = C_APDU(ins=0xb0,le=0xfe) def change_dir(self, fid = None): diff --git a/cards/tcos_card.py b/cards/tcos_card.py index c5c7579..153a5be 100644 --- a/cards/tcos_card.py +++ b/cards/tcos_card.py @@ -441,7 +441,7 @@ class TCOS_Security_Environment(object): self.keys[keyref] = keyvalue class TCOS_Card(ISO_7816_4_Card,building_blocks.Card_with_80_aa): - DRIVER_NAME = "TCOS 2.0" + DRIVER_NAME = ["TCOS 2.0"] APDU_DELETE_FILE = C_APDU(cla=0x80,ins=0xe4) SELECT_P2 = 0x04 @@ -681,7 +681,7 @@ class TCOS_Card(ISO_7816_4_Card,building_blocks.Card_with_80_aa): } class TCOS_3_Card(TCOS_Card): - DRIVER_NAME = "TCOS 3.0" + DRIVER_NAME = ["TCOS 3.0"] APDU_DELETE_FILE = C_APDU(cla=0x80,ins=0xe4) SELECT_P2 = 0x04 LS_L_SIZE_TAG = 0x80 diff --git a/cyberflex-shell.py b/cyberflex-shell.py index ac3de93..e617625 100755 --- a/cyberflex-shell.py +++ b/cyberflex-shell.py @@ -290,7 +290,7 @@ class Cyberflex_Shell(Shell): _obj = getattr(cards, i) if driver_name.lower() == i.lower(): return _obj - if hasattr(_obj, "DRIVER_NAME") and driver_name.lower() == getattr(_obj, "DRIVER_NAME").lower(): + if hasattr(_obj, "DRIVER_NAME") and driver_name.lower() in [e.lower() for e in getattr(_obj, "DRIVER_NAME")]: return _obj raise NameError, "Class not found"