Beispiel #1
0
 def formatResult(self, seekable, le, data, sw, sm):
     r = R_APDU(Iso7816OS.formatResult(self, seekable, le, data, sw, sm))
     # The Belpic applet provides a bogus file length of 65536 for
     # every file, and does not return an error or warning when the
     # actual file length is shorter that the file as found; so
     # filter out the EOFBEFORENEREAD warning
     if (r.sw1 == 0x62 and r.sw2 == 0x82):
         logging.info("Filtering out warning")
         r.sw = "9000".decode("hex")
     return r.render()
Beispiel #2
0
    def test_RAPDU(self):
        e = R_APDU(0x90, 0)
        f = R_APDU("foo\x67\x00")

        print()
        print(e)
        print(f)
        print()
        print(repr(e))
        print(repr(f))

        print()
        for i in e, f:
            print(hexdump(i.render()))
Beispiel #3
0
    def formatResult(self, seekable, le, data, sw, sm):
        if seekable:
            # when le = 0 then we want to have 0x9000. here we only have the
            # effective le, which is either MAX_EXTENDED_LE or MAX_SHORT_LE,
            # depending on the APDU. Note that the following distinguisher has
            # one false positive
            if le > len(data) and le != MAX_EXTENDED_LE and le != MAX_SHORT_LE:
                sw = SW["WARN_EOFBEFORENEREAD"]

        if le != None:
            result = data[:le]
        else:
            result = data[:0]
        if sm:
            try:
                sw, result = self.SAM.protect_result(sw, result)
            except SwError as e:
                logging.info(e.message)
                import traceback
                traceback.print_exception(*sys.exc_info())
                sw = e.sw
                result = ""
                answer = self.formatResult(False, 0, result, sw, False)

        return R_APDU(result, inttostring(sw)).render()
Beispiel #4
0
    def formatResult(self, ins, le, data, sw):
        if le == 0 and len(data):
            # cryptoflex does not inpterpret le==0 as maxle
            self.lastCommandSW = sw
            self.lastCommandOffcut = data
            r = R_APDU(inttostring(SW["ERR_WRONGLENGTH"] +\
                    min(0xff, len(data)))).render()
        else:
            if ins == 0xa4 and len(data):
                # get response should be followed by select file
                self.lastCommandSW = sw
                self.lastCommandOffcut = data
                r = R_APDU(inttostring(SW["NORMAL_REST"] +\
                    min(0xff, len(data)))).render()
            else:
                r = Iso7816OS.formatResult(self, Iso7816OS.seekable(ins), le, data, sw, False)

        return r
Beispiel #5
0
    def formatResult(self, seekable, le, data, sw, sm):
        if not seekable:
            self.lastCommandOffcut = data[le:]
            l = len(self.lastCommandOffcut)
            if l == 0:
                self.lastCommandSW = SW["NORMAL"]
            else:
                self.lastCommandSW = sw
                sw = SW["NORMAL_REST"] + min(0xff, l)
        else:
            if le > len(data):
                sw = SW["WARN_EOFBEFORENEREAD"]

        result = data[:le]
        if sm:
            sw, result = self.SAM.protect_result(sw, result)

        return R_APDU(result, inttostring(sw)).render()