def update(self):

        if DeviceManager().ifDLLPathExists():
            self.app.setStatusbar("动态库加载于 " + DeviceManager().getDLLPath(), 0)
        else:
            self.app.setStatusbar("动态库不存在于 " + DeviceManager().getDLLPath(), 0)

        self.app.setStatusbar("设备个数 = " + str(DeviceManager().getDeviceCount()), 1)
        # print("currentLogIDs \n")
        currentLogIDs = [o.getID() for o in self.logList]
        updatedLogIDs = [o.getID() for o in LogManager().logList]
        self.logList = copy.copy(LogManager().logList)
        addedLogIDs = [item for item in updatedLogIDs if item not in currentLogIDs]

        # print(str(len(currentLogIDs)) + " " + str(len(updatedLogIDs)) + " " + str(len(addedLogIDs)))

        addedLogs = []
        for logID in addedLogIDs:
            logInstance = next((item for item in self.logList if item.getID() == logID),None)
            if logInstance != None:
                addedLogs.append(logInstance.stringRepresentation())

        self.app.addListItems("logListBox",addedLogs)

        selected = self.app.getListItems("testListBox")
        self.app.clearListBox("testListBox")
        self.app.addListItems("testListBox", TestManager().listOfInfo())
        self.app.selectListItem("testListBox",selected)


        self.timer = Timer(0.5, self.update)
        self.timer.start()
    def topMenuPress(self,name):
        if name == "REFRESH":
            self.app.setStatusbar("设备个数 = " + str(DeviceManager().getDeviceCount()), 1)
        elif name == "HELP":
            self.app.infoBox("COS TEST TOOL 帮助", "COS USB KEY 测试软件")
        elif name == "OFF":
            sys.exit()
        elif name == "SETTINGS":
            pass
        elif name == "SAVE":
            LogManager().saveLogs()
        elif name == "OPEN":
            path = LogManager().getLogsPath()
            if platform.system() == "Windows":
                os.startfile(path)
            elif platform.system() == "Darwin":
                subprocess.Popen(["open", path])
            else:
                subprocess.Popen(["xdg-open", path])
        elif name == 'NEW':
            inputString = self.app.textBox("Input APDU","APDU HERE")
            if inputString != None:
                dict = DeviceManager().sendAPDUStr(inputString)
                print(dict)

        pass
示例#3
0
    def run(self):

        # SELECT MF
        LogManager().addLogStr("WILL SELECT MF", LogType.Info, self.getTestType())
        dict = Helper().getSelectFileDict(FileLocationType.MF)
        if (dict != None) and ('statCode' in dict):
            statCode = dict["statCode"].statCode
            if statCode != StatCodeType.STAT_CODE_SUCCESS:
                return False

        # SELECT ADF
        LogManager().addLogStr("WILL SELECT ADF", LogType.Info, self.getTestType())
        dict = Helper().getSelectFileDict(FileLocationType.ADF)
        if (dict != None) and ('statCode' in dict):
            statCode = dict["statCode"].statCode
            if statCode != StatCodeType.STAT_CODE_SUCCESS:
                return False


        new_pin = "2345"
        pin = "1234"
        hexifiedPin = Helper().getMd5HashHex(new_pin)
        print(hexifiedPin)
        hexifiedPin = Helper().replaceFFWithFE(hexifiedPin)
        print(hexifiedPin)

        randomMsg = Helper().getChallengeMsg()
        if randomMsg == None:
            print("TEST_MODIFY_PIN FALSE")
            return False

        m = hashlib.md5()
        newPinUTF8 = new_pin.encode('utf-8')
        m.update(newPinUTF8)
        h = m.hexdigest().lower()
        h = Helper().replaceFFWithFE(h).lower()
        h1 = '5500' + h
        h2 = '{:02X}'.format(len(h1)) + h1
        k = pyDes.triple_des(bytes.fromhex('12345678214365871122aabb3344cdef'), pyDes.ECB, b"\0\0\0\0\0\0\0\0",
                             pad=None, padmode=pyDes.PAD_PKCS5)
        h3 = binascii.hexlify(k.encrypt(bytes.fromhex(h2))).decode('utf-8')
        h4 = "84F40900" + '{:02X}'.format(len(h3) + 4) + h3.upper()
        r = randomMsg

        #h40 = '84F40900' + str(hex(int(len(h3) / 2)))[2:] + h3.upper()
        #h41 = '84F40900' + str(hex(int(len(h3) / 2)))[2:] + h3.upper()

        mac = self.PBOC_3DES_MAC("12345678214365871122aabb3344cdef",r,h4)
        apdu = h4 + mac.upper()
        return_msg = DeviceManager().sendAPDUStr(apdu)
        if return_msg["statCode"].sw1 == '90' and return_msg["statCode"].sw2 == '00':
            print('TEST_MODIFY_PIN SUCCESS')
        else :
            print("TEST_MODIFY_PIN FALSE")
            return False
 def getGenKeyPairDict(self):
     apdu = APDU({
         "CLA": "00",
         "INS": "46",
         "P1": "00",
         "P2": "00",
         "Lc": "02",
         "Data": "0400",
         "Le": None
     })
     print("getGenKeyPairDict apdu = " + apdu.stringRepresentation())
     dict = DeviceManager().sendAPDU(apdu)
     print("getGenKeyPairDict Dict = " + str(dict))
     return dict
 def getSelectFileDict(self, pos):
     LogManager().addLogStr("Selecting File For Pos:" + str(pos))
     print("Selecting File with Pos" + str(pos))
     apdu = APDU({
         "CLA": "00",
         "INS": "A4",
         "P1": "00",
         "P2": "00",
         "Lc": "02",
         "Data": self.getFID(pos),
         "Le": None
     })
     dict = DeviceManager().sendAPDU(apdu)
     return dict
 def getBinaryWriteDict(self, p1, p2, data):
     apdu = APDU({
         "CLA": "00",
         "INS": "D6",
         "P1": p1,
         "P2": p2,
         "Lc": '{:02X}'.format(len(data)),
         "Data": data,
         "Le": None
     })
     print("getBinaryReadDict apdu = " + apdu.stringRepresentation())
     dict = DeviceManager().sendAPDU(apdu)
     print("getBinaryReadDict Dict = " + str(dict))
     return dict
 def getBinaryReadDict(self, p1, p2, length="08"):
     apdu = APDU({
         "CLA": "00",
         "INS": "B0",
         "P1": p1,
         "P2": p2,
         "Lc": None,
         "Data": None,
         "Le": length
     })
     print("getBinaryReadDict apdu = " + apdu.stringRepresentation())
     dict = DeviceManager().sendAPDU(apdu)
     print("getBinaryReadDict Dict = " + str(dict))
     return dict
    def getVerifyPinDict(self, data, KID="00"):
        apdu = APDU({
            "CLA": "00",
            "INS": "82",
            "P1": "00",
            "P2": KID,
            "Lc": "08",
            "Data": data,
            "Le": None
        })

        print("getVerifyPinDict apdu = " + apdu.stringRepresentation())
        dict = DeviceManager().sendAPDU(apdu)
        print("getVerifyPinDict Dict = " + str(dict))
        return dict
    def getMSEGenParDict(self, KID="00", usage="22", additionLength=4):
        apdu = APDU({
            "CLA": "00",
            "INS": "22",
            "P1": "01",
            "P2": "B8",
            "Lc": '{:02X}'.format(4 + additionLength),
            "Data": "8302" + KID + usage,
            "Le": None
        })

        print("getPubKeyDict apdu = " + apdu.stringRepresentation())
        dict = DeviceManager().sendAPDU(apdu)
        print("getPubKeyDict Dict = " + str(dict))
        return dict
    def runButtonPress(self,btn):

        if DeviceManager().getDeviceCount() <= 0:
            self.app.warningBox("当前无设备链接", "请插入 USB KEY")
            return

        selected = self.app.getListItems("testListBox")
        print(selected)
        try:
            for name in selected:
                TestManager().runTest(name)
        except:
            # LogManager().addLogStr("ERROR WHEN RUN TEST",LogType.Error,TestType.COMMON_EVENT)
            pass

        pass
示例#11
0
    def getPubKeyDict(self, KID="00"):
        LogManager().addLogStr("Getting Public Key Dict For KID = " + str(KID))
        apdu = APDU({
            "CLA": "80",
            "INS": "E6",
            "P1": "2A",
            "P2": KID,
            "Lc": None,
            "Data": None,
            "Le": "FF"
        })

        print("getPubKeyDict apdu = " + apdu.stringRepresentation())
        dict = DeviceManager().sendAPDU(apdu)
        print("getPubKeyDict Dict = " + str(dict))
        return dict
示例#12
0
    def getChallengeMsg(self):
        LogManager().addLogStr("Getting Challenge")
        apdu = APDU({
            "CLA": "00",
            "INS": "84",
            "P1": "00",
            "P2": "00",
            "Lc": None,
            "Data": None,
            "Le": "08"
        })
        dict = DeviceManager().sendAPDU(apdu)
        print("getChallengeMsg Dict =")
        print(dict)
        if (dict != None) and ('statCode' in dict):
            statCode = dict["statCode"].statCode
            if statCode == StatCodeType.STAT_CODE_SUCCESS:
                return dict["msg"]

        return None
    def __init__(self):

        DeviceManager().loadDLL()
        self.app.setSticky("news")
        self.app.setExpand("both")

        self.app.createMenu("Connect")


        tools = ["REFRESH","OPEN" ,"SAVE", "SETTINGS", "HELP", "OFF","NEW"]

        self.app.addToolbar(tools, self.topMenuPress, findIcon=True)

        self.app.addStatusbar(fields=2)

        self.app.addLabel("infoText", "COS USB KEY 测试软件")

        self.app.setStatusbarWidth(70, 0)


        self.app.startPanedFrame("p1",)
        self.app.startLabelFrame("Tests")
        self.app.setSticky("nesw")
        self.app.addListBox("testListBox", [])
        self.app.addButton("Run", self.runButtonPress)
        self.app.stopLabelFrame()

        self.app.startPanedFrame("p2")
        self.app.startLabelFrame("Log")
        self.app.setSticky("nesw")
        self.app.addListBox("logListBox", [])
        self.app.stopLabelFrame()

        self.app.stopPanedFrame()
        self.app.stopPanedFrame()

        self.timer = Timer(0.2, self.update)
        self.timer.start()

        self.app.go()