def inTextChanged(self, _=None): try: key = util.hexstr2list(self.indata.text()) key = [int(d) for d in key] #Read settings inpround = self.inprnd.itemData(self.inprnd.currentIndex()) # Get entire key schedule totalrndstr = "" roundKeys = self.model.getRoundKeys(key, inpround) for i, key in enumerate(roundKeys): totalrndstr += "%2d: " % i for j, bit in enumerate(key): if bit is not None: totalrndstr += str(bit) elif i == 0 and j % 8 == 7: totalrndstr += 'X' else: totalrndstr += '?' totalrndstr += "\n" self.keysched.setText(totalrndstr) except: self.keysched.clear()
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.smartCardAPI.getConnection().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))
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.smartCardAPI.getConnection().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))
def inTextChanged(self, _=None): try: #Read settings inpround = self.inprnd.itemData(self.inprnd.currentIndex()) keytext = self.indata.text() key = util.hexstr2list(keytext) key = [int(d) for d in key] if len(key) != 8: err = "ERR: Len=%d: %s" % (len(key), key) self.keysched.setText(err) return # Get entire key schedule totalrndstr = "" roundKeys = self.model.getRoundKeys(key, inpround) for i, key in enumerate(roundKeys): totalrndstr += "%2d: " % i for j, bit in enumerate(key): if bit is not None: totalrndstr += str(bit) elif i == 0 and j % 8 == 7: totalrndstr += 'X' else: totalrndstr += '?' totalrndstr += "\n" self.keysched.setText(totalrndstr) except NotImplementedError as e: self.keysched.setText("ERR: Key schedule calculation not implemented") except ValueError as e: self.keysched.setText("ERR: could not decode key string %s" % keytext)
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: logging.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): logging.error('Extra data') widget.setHtml(htmlstr)
def inTextChanged(self, data=None): data = self.indata.text() try: newdata = util.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 = self.model.keyScheduleRounds(key, inpround, desired) if len(key) == 32: result.extend( self.model.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 = self.model.keyScheduleRounds(key, inpround, r) str = ["%02x" % t for t in result] str = (delim[1] + delim[0]).join(str) str = delim[0] + str totalrndstr += "%2d: " % r totalrndstr += str + "\n" self.keysched.setText(totalrndstr) except ValueError: self.outkey.setText("ERR in HEX: %s" % data)
def inTextChanged(self, data=None): data = self.indata.text() try: newdata = util.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 = self.model.keyScheduleRounds(key, inpround, desired) if len(key) == 32: result.extend(self.model.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 = self.model.keyScheduleRounds(key, inpround, r) str = ["%02x" % t for t in result] str = (delim[1] + delim[0]).join(str) str = delim[0] + str totalrndstr += "%2d: " % r totalrndstr += str + "\n" self.keysched.setText(totalrndstr) except ValueError: self.outkey.setText("ERR in HEX: %s" % data)
def setKnownKey(self, strkey): """Override known key by user selection""" try: self._overridedKey = util.hexstr2list(strkey) except ValueError: raise Warning("Key Selection - Could not convert '%s' to hex, key unchanged!" % strkey)