def setKseed(self, dg1): l2 = dg1["5F1F"][44:] b = bac.BAC(None) m = mrz.MRZ(l2) m.checkMRZ() kseed = binToHexRep(b.mrz_information(m)) toSend = CommandAPDU("10", "A7", "00", "00", "18", kseed, "") self._iso7816.transmit(toSend, "Set KSeed") self.log("Kseed set")
def protect(self, apdu): """ Protect the apdu following the doc9303 specification """ cmdHeader = self._maskClassAndPad(apdu) do87 = b"" do97 = b"" tmp = "Concatenate CmdHeader" if (apdu.getData()): tmp += " and DO87" do87 = self._buildD087(apdu) if (apdu.getLe()): tmp += " and DO97" do97 = self._buildD097(apdu) M = cmdHeader + do87 + do97 self.log(tmp) self.log("\tM: " + binToHexRep(M)) self._ssc = self._incSSC() self.log("Compute MAC of M") self.log("\tIncrement SSC with 1") self.log("\t\tSSC: " + binToHexRep(self._ssc)) N = pad(self._ssc + M) self.log("\tConcateate SSC and M and add padding") self.log("\t\tN: " + binToHexRep(N)) CC = mac(self._ksmac, N) self.log("\tCompute MAC over N with KSmac") self.log("\t\tCC: " + binToHexRep(CC)) do8e = self._buildD08E(CC) size = str(len(do87) + len(do97) + len(do8e)) protectedAPDU = cmdHeader[:4] + intToBin( size) + do87 + do97 + do8e + hexToBin(0x00) self.log("Construct and send protected APDU") self.log("\tProtectedAPDU: " + binToHexRep(protectedAPDU)) return CommandAPDU(binToHexRep(protectedAPDU[0]), binToHexRep(protectedAPDU[1]), binToHexRep(protectedAPDU[2]), binToHexRep(protectedAPDU[3]), binToHexRep(protectedAPDU[4]), binToHexRep(protectedAPDU[5:-1]), binToHexRep(protectedAPDU[-1]))
def _autoDetect(self): """ Pool every connected reader with every driver available by the factory. When a couple (driver, num reader) can select the AID, we have a good reader! Return a couple (reader object, reader number, reader name) """ for driver in ReaderManager.readers: r = self.create(driver) for numR in range(len(self.getReaderList())): try: if r.connect(numR): res = r.transmit(CommandAPDU("00", "A4", "04", "0C", "07", "A0000002471001")) if res.sw1 == 0x90 and res.sw2 == 0x00: return r except ReaderException as msg: r.disconnect() return None