示例#1
0
    def readHeader(self):
        try:
            header = hexRepToBin(self.field1Form.get())
            (bodySize, offset) = asn1.asn1Length(header[1:])
            bodySize = hexToHexRep(bodySize)
            offset = hexToHexRep(offset + 1)
            self.writeToLog("HEADER:\n  Body size: {0}\n  Offset: {1}".format(
                bodySize, offset))

            self.field1Form.delete(0, END)
            self.field2Form.delete(0, END)
            self.field1Form.insert(0, bodySize)
            self.field2Form.insert(0, offset)
        except Exception, msg:
            tkMessageBox.showerror("Error: Read header", str(msg))
示例#2
0
    def readHeader(self):
        try:
            header = hexRepToBin(self.field1Form.get())
            (bodySize, offset) = asn1.asn1Length(header[1:])
            bodySize = hexToHexRep(bodySize)
            offset = hexToHexRep(offset+1)
            self.writeToLog("HEADER:\n  Body size: {0}\n  Offset: {1}".format(bodySize,
                                                                              offset))

            self.field1Form.delete(0, END)
            self.field2Form.delete(0, END)
            self.field1Form.insert(0, bodySize)
            self.field2Form.insert(0, offset)
        except Exception, msg:
            tkMessageBox.showerror("Error: Read header", str(msg))
示例#3
0
    def send(self):
        try:
            self.initIso7816()

            cla = self.customCLAForm.get()
            ins = self.customINSForm.get()
            p1 = self.customP1Form.get()
            p2 = self.customP2Form.get()
            lc = self.customLCForm.get()
            data = self.customDATAForm.get()
            le = self.customLEForm.get()

            if not lc:
                if data:
                    lc = hexToHexRep(len(data)/2)

            toSend = apdu.CommandAPDU(cla, ins, p1, p2, lc, data, le)

            ans = self._iso7816.transmitRaw(toSend)
            rep = binToHexRep(ans.res)
            sw1 = ans.sw1
            sw2 = ans.sw2
            self.writeToLog("REQUEST:\n  APDU: CLA:{0} INS:{1} P1:{2} P2:{3} LC:{4} DATA:{5} LE:{6}".format(cla, ins, p1, p2, lc, data, le))
            self.writeToLog("RESPONSE:\n  APDU:\n    Data:{0}\n    SW1:{1}\n    SW2:{2}".format(rep, hex(sw1), hex(sw2)))

            self.customRespDataForm.delete(0, END)
            self.customRespDataForm.insert(0, rep)
            self.customSW1Form.delete(0, END)
            self.customSW1Form.insert(0, sw1)
            self.customSW2Form.delete(0, END)
            self.customSW2Form.insert(0, sw2)

        except Exception, msg:
            tkMessageBox.showerror("Error: Send", str(msg))
    def _sendCmdData(self, cmd_data):
        """
        @note: Code fragment from the pyPassport.doc9303.bac.BAC class
        """
        data = binToHexRep(cmd_data)
        lc = hexToHexRep(len(data)/2)
        toSend = apdu.CommandAPDU("00", "82", "00", "00", lc, data, "28")

        return self._iso7816.transmit(toSend, "Mutual Authentication")
示例#5
0
    def _sendCmdData(self, cmd_data):
        """
        @note: Code fragment from the pyPassport.doc9303.bac.BAC class
        """
        data = binToHexRep(cmd_data)
        lc = hexToHexRep(len(data) / 2)
        toSend = apdu.CommandAPDU("00", "82", "00", "00", lc, data, "28")

        return self._iso7816.transmit(toSend, "Mutual Authentication")
    def _sendPair(self, cmd_data="\x55" * 40):
        """Send a message/MAC.
        If the cmd_data is not set, it sends a random pair in order to make sure the MAC check fails
        If set, a wrong message is sent together with a valid MAC in order to pass the MAC check

        @param cmd_data: pair to send
        @type cmd_data: a string of the raw data to send

        @return: The response time together with error message
        """
        self._iso7816.getChallenge()

        data = binToHexRep(cmd_data)
        self.log("Send a message with a wrong MAC")
        self.log("Message/MAC:" + data)
        lc = hexToHexRep(len(data) / 2)
        toSend = apdu.CommandAPDU("00", "82", "00", "00", lc, data, "28")
        starttime = time.time()
        try:
            response = self._iso7816.transmit(toSend, "Wrong MAC")
        except Iso7816Exception, msg:
            response = msg
示例#7
0
    def _sendPair(self, cmd_data="\x55" * 40):
        """Send a message/MAC.
        If the cmd_data is not set, it sends a random pair in order to make sure the MAC check fails
        If set, a wrong message is sent together with a valid MAC in order to pass the MAC check

        @param cmd_data: pair to send
        @type cmd_data: a string of the raw data to send

        @return: The response time together with error message
        """
        self._iso7816.getChallenge()

        data = binToHexRep(cmd_data)
        self.log("Send a message with a wrong MAC")
        self.log("Message/MAC:" + data)
        lc = hexToHexRep(len(data) / 2)
        toSend = apdu.CommandAPDU("00", "82", "00", "00", lc, data, "28")
        starttime = time.time()
        try:
            response = self._iso7816.transmit(toSend, "Wrong MAC")
        except Iso7816Exception, msg:
            response = msg
示例#8
0
    def send(self):
        try:
            self.initIso7816()

            cla = self.customCLAForm.get()
            ins = self.customINSForm.get()
            p1 = self.customP1Form.get()
            p2 = self.customP2Form.get()
            lc = self.customLCForm.get()
            data = self.customDATAForm.get()
            le = self.customLEForm.get()

            if not lc:
                if data:
                    lc = hexToHexRep(len(data) / 2)

            toSend = apdu.CommandAPDU(cla, ins, p1, p2, lc, data, le)

            ans = self._iso7816.transmitRaw(toSend)
            rep = binToHexRep(ans.res)
            sw1 = ans.sw1
            sw2 = ans.sw2
            self.writeToLog(
                "REQUEST:\n  APDU: CLA:{0} INS:{1} P1:{2} P2:{3} LC:{4} DATA:{5} LE:{6}"
                .format(cla, ins, p1, p2, lc, data, le))
            self.writeToLog(
                "RESPONSE:\n  APDU:\n    Data:{0}\n    SW1:{1}\n    SW2:{2}".
                format(rep, hex(sw1), hex(sw2)))

            self.customRespDataForm.delete(0, END)
            self.customRespDataForm.insert(0, rep)
            self.customSW1Form.delete(0, END)
            self.customSW1Form.insert(0, sw1)
            self.customSW2Form.delete(0, END)
            self.customSW2Form.insert(0, sw2)

        except Exception, msg:
            tkMessageBox.showerror("Error: Send", str(msg))
示例#9
0
    def _mutualAuthentication(self, cmd_data):
        data = binToHexRep(cmd_data)
        lc = hexToHexRep(len(data) / 2)
        toSend = apdu.CommandAPDU("00", "82", "00", "00", lc, data, "28")

        return self._iso7816.transmit(toSend, "Mutual Authentication")
示例#10
0
 def _mutualAuthentication(self, cmd_data):
     data = binToHexRep(cmd_data)
     lc = hexToHexRep(len(data)/2)
     toSend = apdu.CommandAPDU("00", "82", "00", "00", lc, data, "28")
     return self._iso7816.transmit(toSend, "Mutual Authentication")