From 1cf70244551d82e3604f465bda5058a571e8dcac Mon Sep 17 00:00:00 2001 From: frankmorgner Date: Fri, 8 Oct 2010 08:44:35 +0000 Subject: [PATCH] - exception handling on power up and power down - added workaround for pyscard bugs #3083586 and #3083254 git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@306 96b47cad-a561-4643-ad3b-153ac7d7599c --- .../src/vpicc/VirtualSmartcard.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/virtualsmartcard/src/vpicc/VirtualSmartcard.py b/virtualsmartcard/src/vpicc/VirtualSmartcard.py index fa74cf4..5af02ab 100644 --- a/virtualsmartcard/src/vpicc/VirtualSmartcard.py +++ b/virtualsmartcard/src/vpicc/VirtualSmartcard.py @@ -348,7 +348,9 @@ class RelayOS(object): # {{{ import smartcard if readernum: - #self.reader = smartcard.System.readers()[readernum] + # XXX this is a workaround, see on sourceforge bug #3083254 + # should better use + # self.reader = smartcard.System.readers()[readernum] self.reader = smartcard.System.listReaders()[readernum] else: self.reader = None @@ -361,10 +363,18 @@ class RelayOS(object): # {{{ return "".join([chr(b) for b in self.session.getATR()]) def powerUp(self): - pass + import smartcard + try: + self.session.getATR() + except smartcard.Exceptions.CardConnectionException: + self.session = smartcard.Session(self.reader) def powerDown(self): - self.session.close() + import smartcard + try: + self.session.close() + except smartcard.Exceptions.CardConnectionException: + pass def reset(self): pass @@ -376,7 +386,14 @@ class RelayOS(object): # {{{ apdu.append(ord(b)) rapdu, sw1, sw2 = self.session.sendCommandAPDU(apdu) - rapdu = rapdu + [sw1, sw2] + + # XXX this is a workaround, see on sourceforge bug #3083586 + # should better use + # rapdu = rapdu + [sw1, sw2] + if rapdu[-2:] == [sw1, sw2]: + pass + else: + rapdu = rapdu + [sw1, sw2] return "".join([chr(b) for b in rapdu]) # }}}