Пример #1
0
 def executeAPDUs(self):
     """Execute APDUs and save results in table"""
     rows = self.table.rowCount()
     for rownum in range(0, rows):
         if self.table.item(rownum, 0).checkState() == Qt.Checked:
             apdu = self.table.cellWidget(rownum, 1).toPlainText()
             apdu = hexstr2list(apdu)
             
             
             txdatalen = apdu[4]
             
             if len(apdu) == 5:                    
                 rxdatalen = txdatalen
                 txdatalen = 0
                 txdata = None
             else:
                 txdata = apdu[5:(5+txdatalen)]
                 
                 if len(apdu) == 5+txdatalen:
                     rxdatalen = 0
                 else:
                     rxdatalen = apdu[5+txdatalen+1]
                                                                                         
             resp = self.driver.sendAPDU(apdu[0], apdu[1], apdu[2], apdu[3], txdata, rxdatalen)
             
             if type(resp) == int:
                 self.table.cellWidget(rownum, 2).setText("%04x"%resp)
             else:
                 payload = ""
                 for d in resp[1]: payload += "%02x "%d
                 payload = payload.rstrip()                    
                 self.table.cellWidget(rownum, 2).setText("%04x: %s"%(resp[0], payload))        
Пример #2
0
    def validateAPDU(self, widget):       
         
        headerstart = "<font color=red>"
        headerend = "</font>"
        
        lenstart = "<font color=blue>"
        lenend = "</font>"
        
        payloadstart = "<font color=green>"
        payloadend = "</font>"
        
        
        #APDU Changed, verify & colour-code text       
        data = hexstr2list(widget.toPlainText())

        htmlstr = ""

        #Validate length - basic
        if len(data) < 5:
            fail = True
        else:            
            #First four bytes are header
            htmlstr += headerstart
            header = data[0:4]
            for d in header:
                htmlstr += "%02x "%d
            htmlstr += headerend
            
            #Next is payload length or response length
            htmlstr += lenstart
            htmlstr += "%02x "%data[4]
            htmlstr += lenend
            
            plen = data[4]
            
            #Have payload
            if len(data) > 5:
                
                #Hmm... bad format!?
                if (len(data)-5) < plen:
                    print "ERROR: Header too short"
                    plen = len(data)-5
                
                payload = data[5:(5+plen)]
                
                htmlstr += payloadstart
                for d in payload:
                    htmlstr += "%02x "%d
                htmlstr += payloadend
                
                if (len(data)-5) > plen:
                    htmlstr += lenstart
                    htmlstr += "%02x "%data[plen+5]
                    htmlstr += lenend
                    
                    if (len(data)-5) != (plen+1):
                        print "ERROR: Extra data"                  
        
            widget.setHtml(htmlstr)
Пример #3
0
    def setKnownKeyStr(self, strkey):
        """Override known key by user selection"""
        try:
            hexkey = hexstr2list(strkey)
            self.override = hexkey

        except ValueError:
            QMessageBox.warning(None, "Key Selection", "Could not convert '%s' to hex, key unchanged!" % strkey)
Пример #4
0
    def setKnownKeyStr(self, strkey):
        """Override known key by user selection"""
        try:
            hexkey = hexstr2list(strkey)
            self.override = hexkey

        except ValueError:
            QMessageBox.warning(None, "Key Selection", "Could not convert '%s' to hex, key unchanged!" % strkey)
Пример #5
0
    def inTextChanged(self, data=None):

        data = self.indata.text()

        try:
            newdata = hexstr2list(data)

            if len(newdata) != 16 and len(newdata) != 32:
                err = "ERR: Len=%d: %s" % (len(newdata), newdata)
                self.outkey.setText(err)
                self.keysched.setText(err)
            else:
                if len(newdata) == 16:
                    self.setKeyLength(128)
                elif len(newdata) == 32:
                    self.setKeyLength(256)

                #Read settings
                delim = self.outmode.itemData(self.outmode.currentIndex())
                desired = 0
                inpround = self.inprnd.itemData(self.inprnd.currentIndex())

                key = newdata

                # Get initial key
                result = keyScheduleRounds(key, inpround, desired)
                if len(key) == 32:
                    result.extend(keyScheduleRounds(key, inpround,
                                                    desired + 1))

                rstr = ["%02x" % t for t in result]
                rstr = (delim[1] + delim[0]).join(rstr)
                rstr = delim[0] + rstr

                self.outkey.setText(rstr)

                # Get entire key schedule
                if len(key) == 16:
                    rnds = 10
                elif len(key) == 32:
                    rnds = 14

                totalrndstr = ""
                for r in range(0, rnds + 1):
                    result = keyScheduleRounds(key, inpround, r)
                    rstr = ["%02x" % t for t in result]
                    rstr = (delim[1] + delim[0]).join(rstr)
                    rstr = delim[0] + rstr
                    totalrndstr += rstr + "\n"

                self.keysched.setText(totalrndstr)

        except ValueError:
            self.outkey.setText("ERR in HEX: %s" % data)
Пример #6
0
    def inTextChanged(self, data=None):

        data = self.indata.text()

        try:
            newdata = hexstr2list(data)

            if len(newdata) != 16 and len(newdata) != 32:
                err = "ERR: Len=%d: %s" % (len(newdata), newdata)
                self.outkey.setText(err)
                self.keysched.setText(err)
            else:
                if len(newdata) == 16:
                    self.setKeyLength(128)
                elif len(newdata) == 32:
                    self.setKeyLength(256)

                #Read settings
                delim = self.outmode.itemData(self.outmode.currentIndex())
                desired = 0
                inpround = self.inprnd.itemData(self.inprnd.currentIndex())

                key = newdata

                # Get initial key
                result = keyScheduleRounds(key, inpround, desired)
                if len(key) == 32:
                    result.extend(keyScheduleRounds(key, inpround, desired + 1))

                rstr = ["%02x" % t for t in result]
                rstr = (delim[1] + delim[0]).join(rstr)
                rstr = delim[0] + rstr

                self.outkey.setText(rstr)

                # Get entire key schedule
                if len(key) == 16:
                    rnds = 10
                elif len(key) == 32:
                    rnds = 14

                totalrndstr = ""
                for r in range(0, rnds+1):
                    result = keyScheduleRounds(key, inpround, r)
                    rstr = ["%02x" % t for t in result]
                    rstr = (delim[1] + delim[0]).join(rstr)
                    rstr = delim[0] + rstr
                    totalrndstr += rstr + "\n"

                self.keysched.setText(totalrndstr)

        except ValueError:
            self.outkey.setText("ERR in HEX: %s" % data)