def __transmit(self, args): """Thread method to transmit an apdu;""" if not self.__checkContext(): return if not self.__checkCardInfo(): return cmd = args[0] t0AutoGetResponse = args[1] handlerArgs = args[2] transtime = 0 try: commandValue = Util.s2vs(cmd) self.__handler.handleAPDUCommand("".join("%02X " %(ord(vb)) for vb in commandValue), handlerArgs) timeStart = timeit.default_timer() rsp = gp.sendApdu(self.__context, self.__cardInfo, None, Util.s2vs(cmd)) timeStop = timeit.default_timer() transtime = timeStop - timeStart self.__handler.handleAPDUResponse("".join("%02X " %(ord(vb)) for vb in rsp), transtime, handlerArgs) if t0AutoGetResponse and (rsp[0] == '\x61') and (len(handlerArgs) == 0): cmd = '\x00\xC0\x00\x00' + rsp[1] self.__handler.handleAPDUCommand("".join("%02X " %(ord(vb)) for vb in cmd)) timeStart = timeit.default_timer() rsp = gp.sendApdu(self.__context, self.__cardInfo, None, cmd) timeStop = timeit.default_timer() transtime = timeStop - timeStart self.__handler.handleAPDUResponse("".join("%02X " %(ord(vb)) for vb in rsp), transtime) except Exception, e: self.__handler.handleAPDUResponse('', transtime, handlerArgs) self.__handler.handleException(e)
def __transmit(self, args): """Thread method to transmit an apdu;""" if not self.__checkContext(): return if not self.__checkCardInfo(): return cmd = args[0] t0AutoGetResponse = args[1] handlerArgs = args[2] transtime = 0 try: commandValue = Util.s2vs(cmd) self.__handler.handleAPDUCommand( "".join("%02X " % (ord(vb)) for vb in commandValue), handlerArgs) timeStart = timeit.default_timer() rsp = gp.sendApdu(self.__context, self.__cardInfo, None, Util.s2vs(cmd)) timeStop = timeit.default_timer() transtime = timeStop - timeStart self.__handler.handleAPDUResponse( "".join("%02X " % (ord(vb)) for vb in rsp), transtime, handlerArgs) if t0AutoGetResponse and (rsp[0] == '\x61') and (len(handlerArgs) == 0): cmd = '\x00\xC0\x00\x00' + rsp[1] self.__handler.handleAPDUCommand("".join("%02X " % (ord(vb)) for vb in cmd)) timeStart = timeit.default_timer() rsp = gp.sendApdu(self.__context, self.__cardInfo, None, cmd) timeStop = timeit.default_timer() transtime = timeStop - timeStart self.__handler.handleAPDUResponse( "".join("%02X " % (ord(vb)) for vb in rsp), transtime) except Exception, e: self.__handler.handleAPDUResponse('', transtime, handlerArgs) self.__handler.handleException(e)
def __transmit_impl(self, cmd, t0AutoGetResponse, handlerArgs): commandValue = Util.s2vs(cmd) self.__handler.handleAPDUCommand("".join("%02X " %(ord(vb)) for vb in commandValue), handlerArgs) timeStart = timeit.default_timer() rsp = self.__gpInterface.transmit(Util.s2vs(cmd)) timeStop = timeit.default_timer() transtime = timeStop - timeStart self.__handler.handleAPDUResponse("".join("%02X " %(ord(vb)) for vb in rsp), transtime, handlerArgs) if t0AutoGetResponse and (rsp[0] == '\x61') and (len(handlerArgs) == 0): cmd = '\x00\xC0\x00\x00' + rsp[1] self.__handler.handleAPDUCommand("".join("%02X " %(ord(vb)) for vb in cmd)) timeStart = timeit.default_timer() rsp = gp.sendApdu(cmd) timeStop = timeit.default_timer() transtime = timeStop - timeStart self.__handler.handleAPDUResponse("".join("%02X " %(ord(vb)) for vb in rsp), transtime)
def transmit(self, cmd): self.__checkContext() self.__checkCardInfo() return gp.sendApdu(self.__context, self.__cardInfo, None, cmd)
def str_bin(s): for i in len(s) >> 1: pass if __name__ == "__main__": gp.enableTraceMode(True) c = gp.establishContext() readernames = gp.listReaders(c) for i in range(len(readernames)): print('%d - %s' %(i, readernames[i])) i = int(input("Please select one reader: ")) cc = gp.connectCard(c, readernames[i], gp.SCARD_PROTOCOL_T1) gp.sendApdu(c, cc, None, '\x00\xB0\x00\x00\x00') gp.selectApplication(c, cc, '') sc = gp.mutualAuthentication(c, cc, gp.DEFAULT_KEY, gp.DEFAULT_KEY, gp.DEFAULT_KEY, gp.DEFAULT_KEY, 0x00, 0x00, 0x02, 0x15, 0, 0) INFO("Get status:") try: status10 = gp.getStatus(c, cc, None, gp.GET_STATUS_P1_EXECUTABLE_LOAD_FILES_MODULES) INFO(" Status 0x10: " + str(status10)) except: pass try: status20 = gp.getStatus(c, cc, None, gp.GET_STATUS_P1_EXECUTABLE_LOAD_FILES) INFO(" Status 0x20: " + str(status20)) except: pass try: