Example #1
0
    def InternalSendApdu(self, apdu_to_send):
        """Send an APDU to the device.

    Sends an APDU to the device, possibly falling back to the legacy
    encoding format that is not ISO7816-4 compatible.

    Args:
      apdu_to_send: The CommandApdu object to send

    Returns:
      The ResponseApdu object constructed out of the devices reply.
    """
        response = None
        if not self.use_legacy_format:
            response = apdu.ResponseApdu(
                self.transport.SendMsgBytes(apdu_to_send.ToByteArray()))
            if response.sw1 == 0x67 and response.sw2 == 0x00:
                # If we failed using the standard format, retry with the
                # legacy format.
                self.use_legacy_format = True
                return self.InternalSendApdu(apdu_to_send)
        else:
            response = apdu.ResponseApdu(
                self.transport.SendMsgBytes(
                    apdu_to_send.ToLegacyU2FByteArray()))
        return response
Example #2
0
 def testResponseApduCheckSuccessOtherError(self):
   resp = apdu.ResponseApdu(bytearray([0xfa, 0x05]))
   self.assertRaises(errors.ApduError, resp.CheckSuccessOrRaise)
Example #3
0
 def testResponseApduCheckSuccessInvalidKeyHandle(self):
   resp = apdu.ResponseApdu(bytearray([0x6a, 0x80]))
   self.assertRaises(errors.InvalidKeyHandleError, resp.CheckSuccessOrRaise)
Example #4
0
 def testResponseApduCheckSuccessTUPRequired(self):
   resp = apdu.ResponseApdu(bytearray([0x69, 0x85]))
   self.assertRaises(errors.TUPRequiredError, resp.CheckSuccessOrRaise)
Example #5
0
 def testResponseApduParseNoBody(self):
   resp = apdu.ResponseApdu(bytearray([0x69, 0x85]))
   self.assertEqual(resp.sw1, 0x69)
   self.assertEqual(resp.sw2, 0x85)
   self.assertFalse(resp.IsSuccess())
Example #6
0
 def testResponseApduParse(self):
   resp = apdu.ResponseApdu(bytearray([0x05, 0x04, 0x90, 0x00]))
   self.assertEqual(resp.body, bytearray([0x05, 0x04]))
   self.assertEqual(resp.sw1, 0x90)
   self.assertEqual(resp.sw2, 0x00)
   self.assertTrue(resp.IsSuccess())