From 43df314a5ec3adf5ed7d5537b1547e877a98c51d Mon Sep 17 00:00:00 2001 From: oepen Date: Tue, 26 Jul 2011 12:30:18 +0000 Subject: [PATCH] -Moved MAX_LE defines to ConstantDefinitions -Added a parameter to control whether or not an ISO card supports extended length APDUs -Correctly indicating extended length support in the ATR git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@439 96b47cad-a561-4643-ad3b-153ac7d7599c --- .../src/vpicc/virtualsmartcard/ConstantDefinitions.py | 5 ++++- .../src/vpicc/virtualsmartcard/TLVutils.py | 2 -- .../src/vpicc/virtualsmartcard/VirtualSmartcard.py | 11 ++++++++--- virtualsmartcard/src/vpicc/virtualsmartcard/utils.py | 5 +++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/ConstantDefinitions.py b/virtualsmartcard/src/vpicc/virtualsmartcard/ConstantDefinitions.py index 94a2179..a623202 100644 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/ConstantDefinitions.py +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/ConstantDefinitions.py @@ -15,7 +15,10 @@ # # You should have received a copy of the GNU General Public License along with # virtualsmartcard. If not, see . -# + +MAX_SHORT_LE = 0xff +MAX_EXTENDED_LE = 0xffff + # Life cycle status byte {{{ LCB = {} LCB["NOINFORMATION"] = 0x00 diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/TLVutils.py b/virtualsmartcard/src/vpicc/virtualsmartcard/TLVutils.py index 9d7b84d..054bd57 100644 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/TLVutils.py +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/TLVutils.py @@ -45,8 +45,6 @@ TAG["OFFSET_DATA"] = 0x54 TAG["TAG_LIST"] = 0x5C TAG["HEADER_LIST"] = 0x5D TAG["EXTENDED_HEADER_LIST"] = 0x4D -MAX_EXTENDED_LE = 0xffff -MAX_SHORT_LE = 0xff def tlv_unpack(data): # {{{ ber_class = (ord(data[0]) & 0xC0) >> 6 diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py b/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py index b21d3ec..923e2ce 100644 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py @@ -61,7 +61,7 @@ class SmartcardOS(object): # {{{ # }}} class Iso7816OS(SmartcardOS): # {{{ - def __init__(self, mf, sam, ins2handler=None, maxle=MAX_SHORT_LE): + def __init__(self, mf, sam, ins2handler=None, extended_length=False): self.mf = mf self.SAM = sam @@ -107,10 +107,15 @@ class Iso7816OS(SmartcardOS): # {{{ else: self.ins2handler = ins2handler - self.maxle = maxle + if extended_length: + self.maxle = MAX_EXTENDED_LE + else: + self.maxle = MAX_SHORT_LE + self.lastCommandOffcut = "" self.lastCommandSW = SW["NORMAL"] - card_capabilities = self.mf.firstSFT + self.mf.secondSFT + Iso7816OS.makeThirdSoftwareFunctionTable() + card_capabilities = self.mf.firstSFT + self.mf.secondSFT + \ + Iso7816OS.makeThirdSoftwareFunctionTable(extendedLe = extended_length) self.atr = Iso7816OS.makeATR(T=1, directConvention = True, TA1=0x13, histChars = chr(0x80) + chr(0x70 + len(card_capabilities)) + card_capabilities) diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/utils.py b/virtualsmartcard/src/vpicc/virtualsmartcard/utils.py index d917c6c..ede6381 100644 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/utils.py +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/utils.py @@ -17,6 +17,7 @@ # virtualsmartcard. If not, see . # import string, binascii +from ConstantDefinitions import MAX_SHORT_LE, MAX_EXTENDED_LE def stringtoint(str): # {{{ #i = len(str) - 1 @@ -298,9 +299,9 @@ class C_APDU(APDU): def effective_Le(self): if hasattr(self, "_Le") and (self.Le == 0): if self.__extended_length: - return 0xffff + return MAX_EXTENDED_LE else: - return 0xff + return MAX_SHORT_LE else: return self.Le