API change: DRIVER_NAME now is a (merged) list
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@187 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
parent
375705a6f1
commit
98f1dbe110
|
@ -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.
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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])
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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??", )
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue