From 425e054916d907b177a7609b1f18456cb7fa2447 Mon Sep 17 00:00:00 2001 From: frankmorgner Date: Mon, 11 Oct 2010 12:31:13 +0000 Subject: [PATCH] activated ATR polling as workaround for pyscard bug #3084449. now when the real smartcard is removed, the relay process terminates git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@318 96b47cad-a561-4643-ad3b-153ac7d7599c --- virtualsmartcard/src/vpcd/vpcd.c | 8 +++++-- .../src/vpicc/VirtualSmartcard.py | 21 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/virtualsmartcard/src/vpcd/vpcd.c b/virtualsmartcard/src/vpcd/vpcd.c index 4d045c3..2f09b30 100644 --- a/virtualsmartcard/src/vpcd/vpcd.c +++ b/virtualsmartcard/src/vpcd/vpcd.c @@ -189,9 +189,13 @@ int vicc_transmit(int apdu_len, const char *apdu, char **rapdu) { } int vicc_present(void) { - if (client_sock > 0) + if (client_sock > 0) { + char *atr = NULL; + if (vicc_getatr(&atr) < 0) + return 0; + free(atr); return 1; - else { + } else { /* Wait up to one microsecond. */ client_sock = waitforclient(server_sock, 0, 1); if (client_sock < 0) diff --git a/virtualsmartcard/src/vpicc/VirtualSmartcard.py b/virtualsmartcard/src/vpicc/VirtualSmartcard.py index 7d7080c..89789d1 100644 --- a/virtualsmartcard/src/vpicc/VirtualSmartcard.py +++ b/virtualsmartcard/src/vpicc/VirtualSmartcard.py @@ -378,7 +378,7 @@ class RelayOS(SmartcardOS): # {{{ if removed.reader == self.os.reader: if removed.atr == self.os.atr: print "Card removed from '%s'. Terminating." % self.os.reader - sys.exit() + self.os.exit = True # }}} @@ -392,6 +392,8 @@ class RelayOS(SmartcardOS): # {{{ # should better use # self.reader = smartcard.System.readers()[readernum] self.reader = readers[readernum] + # set exit to True if you want to terminate relaying + self.exit = False try: self.session = smartcard.Session(self.reader) except smartcard.Exceptions.CardConnectionException, e: @@ -403,15 +405,18 @@ class RelayOS(SmartcardOS): # {{{ print "Connected to card in '%s'" % self.reader - atexit.register(self.stop) - - def stop(self): - self.session.close() + atexit.register(self.session.close) def getATR(self): + if self.exit: + sys.exit() + return "".join([chr(b) for b in self.atr]) def powerUp(self): + if self.exit: + sys.exit() + import smartcard try: self.session.getATR() @@ -420,9 +425,15 @@ class RelayOS(SmartcardOS): # {{{ self.atr = self.session.getATR() def powerDown(self): + if self.exit: + sys.exit() + self.session.close() def execute(self, msg): + if self.exit: + sys.exit() + #apdu = [].append(ord(b) for b in msg) apdu = [] for b in msg: