def before_send(self, apdu):
     self.last_vanilla_c_apdu = C_APDU(apdu)
     if (apdu.cla & 0x80 != 0x80) and (apdu.CLA & 0x0C != 0x0C):
         # Transform for SM
         apdu.CLA = apdu.CLA | 0x0C
         apdu_string = binascii.b2a_hex(apdu.render())
         new_apdu = [apdu_string[:8]]
         new_apdu.append("YY")
         
         if apdu.case() in (3,4):
             new_apdu.append("87[01")
             new_apdu.append(binascii.b2a_hex(apdu.data))
             new_apdu.append("]")
         
         if apdu.case() in (2,4):
             if apdu.Le == 0:
                 apdu.Le = 0xe7 # FIXME: Probably not the right way
             new_apdu.append("97(%02x)" % apdu.Le)
         
         new_apdu.append("8E()00")
         
         new_apdu_string = "".join(new_apdu)
         apdu = C_APDU.parse_fancy(new_apdu_string)
     
     return TCOS_Security_Environment.before_send(self, apdu)
示例#2
0
    def before_send(self, apdu):
        self.last_vanilla_c_apdu = C_APDU(apdu)
        if (apdu.cla & 0x80 != 0x80) and (apdu.CLA & 0x0C != 0x0C):
            # Transform for SM
            apdu.CLA = apdu.CLA | 0x0C
            apdu_string = binascii.b2a_hex(apdu.render())
            new_apdu = [apdu_string[:8]]
            new_apdu.append("YY")

            if apdu.case() in (3, 4):
                new_apdu.append("87[01")
                new_apdu.append(binascii.b2a_hex(apdu.data))
                new_apdu.append("]")

            if apdu.case() in (2, 4):
                if apdu.Le == 0:
                    apdu.Le = 0xdf  # FIXME: Probably not the right way
                new_apdu.append("97(%02x)" % apdu.Le)

            new_apdu.append("8E()00")

            new_apdu_string = "".join(new_apdu)
            apdu = C_APDU.parse_fancy(new_apdu_string)

        return TCOS_Security_Environment.before_send(self, apdu)