def testcase_ISO7816_8ErrorChecker(self): """Test ISO7816_4ErrorChecker.""" ecs = ISO7816_8ErrorChecker() tiso7816_8SW = { 0x63: (smartcard.sw.SWExceptions.WarningProcessingException, [0x00] + range(0xc0, 0xcf + 1)), 0x65: (smartcard.sw.SWExceptions.ExecutionErrorException, [0x81]), 0x66: (smartcard.sw.SWExceptions.SecurityRelatedException, [0x00, 0x87, 0x88]), 0x67: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), 0x68: (smartcard.sw.SWExceptions.CheckingErrorException, [0x83, 0x84]), 0x69: (smartcard.sw.SWExceptions.CheckingErrorException, range(0x82, 0x85 + 1)), 0x6A: (smartcard.sw.SWExceptions.CheckingErrorException, [0x81, 0x82, 0x86, 0x88]), } for sw1 in range(0x00, 0xff + 1): sw2range = [] if tiso7816_8SW.has_key(sw1): exception, sw2range = tiso7816_8SW[sw1] for sw2 in range(0x00, 0xff + 1): if sw2 in sw2range: self.assertRaises(exception, ecs, [], sw1, sw2) else: ecs([], sw1, sw2)
def connectReaderFromCardFun(envi, cardIndex=None): "establish a link between the shell and a card" if "connection" in envi and envi["connection"] != None: print "there is already a connection to reader " + envi[ "connectedReader"] return if cardIndex == None: indice = 0 if len(cardobserver.cardList) > 1: Executer.printOnShell( "Warning : the information comes from the first card available in the list, there are others cards" ) else: indice = cardIndex if len(cardobserver.cardList) == 0: Executer.printOnShell("there is no card available") return try: card = cardobserver.cardList[indice] except IndexError: Executer.printOnShell("invalid indice") return False try: envi["connection"] = card.createConnection( ) #create a connection on the reader except Exception as e: Executer.printOnShell(str(e)) return False try: envi["connection"].connect() #create a connection on the card except Exception as e: del envi["connection"] Executer.printOnShell(str(e)) return False card.connection = envi["connection"] card.connection.card = card envi["connectedReader"] = card.connection.getReader() errorchain = [] errorchain = [ ErrorCheckingChain(errorchain, ISO7816_8ErrorChecker()), ErrorCheckingChain(errorchain, ISO7816_9ErrorChecker()), ErrorCheckingChain(errorchain, ISO7816_4ErrorChecker()) ] envi["connection"].setErrorCheckingChain(errorchain) return True
def __init__(self): self.curreader = None self.s = None self.reset() self.command_acc = "" # empty unterminated command # error detection errorchain = [] errorchain = [ErrorCheckingChain(errorchain, ISO7816_9ErrorChecker())] errorchain = [ErrorCheckingChain(errorchain, ISO7816_8ErrorChecker())] errorchain = [ErrorCheckingChain(errorchain, ISO7816_4ErrorChecker())] self.errorchain = errorchain # readline history histfile = os.path.expanduser('~/.scriptim_history') try: init_history(histfile) except NameError: pass
def testcase_ISO78164_Test_ErrorCheckingChain_filtering(self): """Test error chain with ISO7816-4 checker followed by Test checker.""" errorchain = [] errorchain = [ ErrorCheckingChain(errorchain, ISO7816_8ErrorChecker()), ErrorCheckingChain(errorchain, ISO7816_4ErrorChecker()), ErrorCheckingChain(errorchain, ISO7816_4_SW1ErrorChecker()) ] # don't care about Warning Exceptions errorchain[0].addFilterException( smartcard.sw.SWExceptions.WarningProcessingException) for sw2 in range(0x00, 0xff): # should not raise errorchain[0]([], 0x62, sw2) errorchain[0]([], 0x63, sw2) # should raise self.assertRaises( smartcard.sw.SWExceptions.ExecutionErrorException, errorchain[0], [], 0x64, sw2)
def __init__(self, connection=None): self.connection = connection self.ef = None self.ef_size = None self.cached_efs = {} self.start_time = time() self.part_start_time = {} if not self.connection: r = get_first_reader() self.connection = r.createConnection() errorchain = [] errorchain = [ErrorCheckingChain(errorchain, ISO7816_9ErrorChecker())] errorchain = [ErrorCheckingChain(errorchain, ISO7816_8ErrorChecker())] errorchain = [ErrorCheckingChain(errorchain, ISO7816_4ErrorChecker())] self.connection.setErrorCheckingChain(errorchain) self.connection.addSWExceptionToFilter(WarningProcessingException) # observer = ConsoleCardConnectionObserver() # self.connection.addObserver(observer) self.connection.connect()
from smartcard.sw.ErrorCheckingChain import ErrorCheckingChain from smartcard.sw.ISO7816_4ErrorChecker import ISO7816_4ErrorChecker from smartcard.sw.ISO7816_8ErrorChecker import ISO7816_8ErrorChecker from smartcard.sw.SWExceptions import SWException, WarningProcessingException import hashlib # request any card cardtype = AnyCardType() cardrequest = CardRequest(timeout=10, cardType=cardtype) cardservice = cardrequest.waitforcard() # our error checking chain errorchain = [] errorchain = [ ErrorCheckingChain(errorchain, ISO7816_8ErrorChecker()), ErrorCheckingChain(errorchain, ISO7816_4ErrorChecker()) ] cardservice.connection.setErrorCheckingChain(errorchain) # a console tracer observer = ConsoleCardConnectionObserver() cardservice.connection.addObserver(observer) # send a few apdus; exceptions will occur upon errors cardservice.connection.connect() def as_list(ba): return [x for x in ba]
# coding=utf-8 from smartcard.sw.ErrorCheckingChain import ErrorCheckingChain from smartcard.sw.ISO7816_4ErrorChecker import ISO7816_4ErrorChecker from smartcard.sw.ISO7816_8ErrorChecker import ISO7816_8ErrorChecker from smartcard.sw.ISO7816_9ErrorChecker import ISO7816_9ErrorChecker ErrorChainWrapper = [] ErrorChainWrapper = [ ErrorCheckingChain(ErrorChainWrapper, ISO7816_9ErrorChecker()) ] ErrorChainWrapper = [ ErrorCheckingChain(ErrorChainWrapper, ISO7816_8ErrorChecker()) ] ErrorChainWrapper = [ ErrorCheckingChain(ErrorChainWrapper, ISO7816_4ErrorChecker()) ]