From a766a6e01aff0e3de21d9cbf0723dff689dfe9c5 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Thu, 18 Jul 2013 14:09:38 +0200 Subject: [PATCH] fixed handling of SW1=0x61 in handler_test --- .../virtualsmartcard/VirtualSmartcard.py | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py b/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py index 3b39226..9ccd0c6 100644 --- a/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py +++ b/virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py @@ -568,38 +568,37 @@ class HandlerTestOS(SmartcardOS): ok = '\x90\x00' error = '\x6d\x00' if msg == '\x00\xA4\x04\x00\x06\xA0\x00\x00\x00\x18\x50' or msg == '\x00\xA4\x04\x00\x06\xA0\x00\x00\x00\x18\xFF': - print 'Select applet' + logging.info('Select applet') return ok elif msg.startswith('\x80\x38\x00'): - print 'Time Request' + logging.info('Time Request') return ok elif msg == '\x80\x30\x00\x00': - print 'Case 1, APDU' + logging.info('Case 1, APDU') return ok elif msg == '\x80\x30\x00\x00\x00': - print 'Case 1, TPDU' + logging.info('Case 1, TPDU') return ok elif msg.startswith('\x80\x32\x00\x00'): - print 'Case 3' + logging.info('Case 3') return ok elif msg.startswith('\x80\x34'): - print 'Case 2' + logging.info('Case 2') return self.__output_from_le(msg) + ok elif msg.startswith('\x80\x36'): if len(msg) == 5+ord(msg[4]): - print 'Case 4, TPDU' + logging.info('Case 4, TPDU') self.lastCommandOffcut = self.__output_from_le(msg) - # XXX the return code is expected by handler_test.c. According - # to ISO 7816 this should be: - # '\x61' + chr(max(0xff, len(self.lastCommandOffcut))) - return '\x61' + chr(len(self.lastCommandOffcut)&0xFF) + if len(self.lastCommandOffcut) > 0xFF: + return '\x61\x00' + return '' + chr(len(self.lastCommandOffcut)&0xFF) elif len(msg) == 6+ord(msg[4]): - print 'Case 4, APDU' + logging.info('Case 4, APDU') return self.__output_from_le(msg) + ok else: return error elif msg.startswith('\x80\xC0\x00\x00'): - print 'Get response' + logging.info('Get response') out = self.lastCommandOffcut[:ord(msg[4])] self.lastCommandOffcut = self.lastCommandOffcut[ord(msg[4]):] return out + ok