Example #1
0
    def test_signed_wrong_firmware_upload(self):

        self.client.debug.fill_config()

        # get storage hash so we can compare it after upload
        original_flashed_firmware_hash, storage_hash = self.client.debug.read_memory_hashes(
        )

        data = open('firmware_images/signed_firmware_wrong.bin', 'r').read()
        firmware_hash = hashlib.sha256(data)

        # erase firmware
        ret = self.client.call(proto.FirmwareErase())
        self.assertIsInstance(ret, proto.Success)

        # upload firmware
        ret = self.client.call_raw(
            proto.FirmwareUpload(payload_hash=firmware_hash.digest(),
                                 payload=data))
        self.assertIsInstance(ret, proto.Success)

        self.reconnect()

        # get flased hashes
        flashed_firmware_hash, storage_hash_after = self.client.debug.read_memory_hashes(
        )

        # check that the flashed hash is the same as we calculated client side
        self.assertEquals(firmware_hash.hexdigest(),
                          binascii.hexlify(flashed_firmware_hash))

        # make sure config flash did not get copied over
        self.assertNotEquals(storage_hash, storage_hash_after)
Example #2
0
    def test_unsigned_firmware_upload(self):

        # get storage hash so we can compare it after upload
        original_flashed_firmware_hash, storage_hash = self.client.debug.read_memory_hashes(
        )

        data = open('firmware_images/firmware_no_magic.bin', 'r').read()
        firmware_hash = hashlib.sha256(data)

        # erase firmware
        ret = self.client.call(proto.FirmwareErase())
        self.assertIsInstance(ret, proto.Success)

        # upload firmware
        ret = self.client.call_raw(
            proto.FirmwareUpload(payload_hash=firmware_hash.digest(),
                                 payload=data))
        self.assertIsInstance(ret, proto.Failure)
        self.assertEquals(ret.message, 'Not valid firmware')