예제 #1
0
    def _parse_heads_updates(self, device):
        """
        Parses heads updates info.

        Keyword arguments:
        device -- Model of the updated device
        """
        self.heads_update_url = None
        self.heads_update_sha = None
        self.heads_update_version = None
        heads_metadata_info = None
        root = ET.fromstring(self.metadata_info)
        for component in root.findall("component"):
            if f"heads.{device}" in component.find("id").text:
                heads_metadata_info = component
        if not heads_metadata_info:
            print("No metadata info for chosen board")
            return EXIT_CODES["NO_UPDATES"]
        for release in heads_metadata_info.find("releases").findall("release"):
            release_ver = release.get("version")
            if (self.heads_version == "heads" or
                    l_ver(release_ver) > l_ver(self.heads_version)):
                if (not self.heads_update_version or
                        l_ver(release_ver) > l_ver(self.heads_update_version)):
                    self.heads_update_url = release.find("location").text
                    for sha in release.findall("checksum"):
                        if (".cab" in sha.attrib["filename"]
                                and sha.attrib["type"] == "sha1"):
                            self.heads_update_sha = sha.text
                    self.heads_update_version = release_ver
        if self.heads_update_url:
            return EXIT_CODES["SUCCESS"]
        else:
            print("Heads firmware is up to date.")
            return EXIT_CODES["NO_UPDATES"]
예제 #2
0
 def test_update_firmware_usbvm(self):
     old_version = None
     new_version = None
     self.q._get_dom0_updates()
     self.q._parse_dom0_updates_info(self.q.dom0_updates_info)
     self.q._get_usbvm_devices()
     with open(FWUPD_VM_LOG) as usbvm_device_info:
         raw = usbvm_device_info.read()
         self.q._parse_usbvm_updates(raw)
         for number, device in enumerate(self.q.usbvm_updates_list):
             if "Name" not in device:
                 continue
             if device["Name"] == "ColorHug2":
                 old_version = device["Version"]
                 break
     if old_version is None:
         self.fail("Test device not found")
     user_input = [str(number + 1 + len(self.q.dom0_updates_list)), "1"]
     with patch("builtins.input", side_effect=user_input):
         self.q.update_firmware(usbvm=True)
     self.q._get_usbvm_devices()
     with open(FWUPD_VM_LOG) as usbvm_device_info:
         raw = usbvm_device_info.read()
         usbvm_devices_info_dict = json.loads(raw)
     for device in usbvm_devices_info_dict["Devices"]:
         if "Name" not in device:
             continue
         if device["Name"] == "ColorHug2":
             new_version = device["Version"]
             break
     if new_version is None:
         self.fail("Test device not found")
     self.assertLess(l_ver(old_version), l_ver(new_version))
예제 #3
0
 def _check_fwupdtool_version(self):
     """Checks the fwupd client version and sets fwupdtool path dynamically
     """
     version_check = 'client version:\t1.3.6'
     version_check_old = 'client version:\t1.1.2'
     version_regex = re.compile(
         r'client version:\t[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}$'
     )
     cmd_version = [
         FWUPDMGR,
         "--version"
     ]
     p = subprocess.Popen(
         cmd_version,
         stdout=subprocess.PIPE
     )
     self.client_version = p.communicate()[0].decode().split("\n")[0]
     if p.returncode != 0 and not os.path.exists(FWUPDNEWS):
         raise Exception("Checking version failed")
     elif p.returncode != 0 and os.path.exists(FWUPDNEWS):
         with open(FWUPDNEWS, "r") as news:
             self.client_version = news.readline().replace(
                 "Version ",
                 "client version:\t"
             )
             self.client_version = self.client_version.replace("\n", "")
     assert version_regex.match(self.client_version), (
         'Version command output has changed!!!'
     )
     if l_ver(version_check_old) > l_ver(self.client_version):
         self.fwupd_hwids = FWUPDMGR
     elif l_ver(version_check) > l_ver(self.client_version):
         self.fwupd_hwids = FWUPDTOOL_OLD
     else:
         self.fwupd_hwids = FWUPDTOOL
예제 #4
0
 def test_downgrade_firmware_usbvm(self):
     old_version = None
     self.q._get_dom0_devices()
     dom0_downgrades = self.q._parse_downgrades(self.q.dom0_devices_info)
     self.q._get_usbvm_devices()
     with open(FWUPD_VM_LOG) as usbvm_device_info:
         raw = usbvm_device_info.read()
         downgrades = self.q._parse_downgrades(raw)
         for number, device in enumerate(downgrades):
             if "Name" not in device:
                 continue
             if device["Name"] == "ColorHug2":
                 old_version = device["Version"]
                 break
     if old_version is None:
         self.fail("Test device not found")
     user_input = [str(number + 1 + len(dom0_downgrades)), "1"]
     with patch("builtins.input", side_effect=user_input):
         self.q.downgrade_firmware(usbvm=True)
     self.q._get_usbvm_devices()
     with open(FWUPD_VM_LOG) as usbvm_device_info:
         raw = usbvm_device_info.read()
         downgrades = self.q._parse_downgrades(raw)
     new_version = downgrades[number]["Version"]
     self.assertGreater(l_ver(old_version), l_ver(new_version))
예제 #5
0
 def test_update_firmware_dom0(self):
     old_version = None
     new_version = None
     self.q._get_dom0_updates()
     self.q._parse_dom0_updates_info(self.q.dom0_updates_info)
     for number, device in enumerate(self.q.dom0_updates_list):
         if "Name" not in device:
             continue
         if device["Name"] == "ColorHug2":
             old_version = device["Version"]
             break
     if old_version is None:
         self.fail("Test device not found")
     user_input = [str(number + 1)]
     with patch("builtins.input", side_effect=user_input):
         self.q.update_firmware()
     self.q._get_dom0_devices()
     dom0_devices_info_dict = json.loads(self.q.dom0_devices_info)
     for device in dom0_devices_info_dict["Devices"]:
         if "Name" not in device:
             continue
         if device["Name"] == "ColorHug2":
             new_version = device["Version"]
             break
     if new_version is None:
         self.fail("Test device not found")
     self.assertLess(l_ver(old_version), l_ver(new_version))
예제 #6
0
    def _parse_downgrades(self, device_list):
        """Parses information about possible downgrades.

        Keywords argument:
        device_list -- list of connected devices
        """
        downgrades = []
        if "No detected devices" in device_list:
            return downgrades
        dom0_devices_info_dict = json.loads(device_list)
        for device in dom0_devices_info_dict["Devices"]:
            if "Releases" in device:
                try:
                    version = device["Version"]
                except KeyError:
                    continue
                downgrades.append({
                    "Name":
                    device["Name"],
                    "Version":
                    device["Version"],
                    "Releases":
                    [{
                        "Version": downgrade["Version"],
                        "Description": downgrade["Description"],
                        "Url": downgrade["Uri"],
                        "Checksum": downgrade["Checksum"][-1],
                    } for downgrade in device["Releases"]
                     if l_ver(downgrade["Version"]) < l_ver(version)],
                })
        return downgrades
예제 #7
0
 def test_downgrade_firmware_dom0(self):
     old_version = None
     self.q.check_fwupd_version()
     if not self.q.fwupdagent_dom0:
         downgrade_firmware = io.StringIO()
         sys.stdout = downgrade_firmware
         self.q.downgrade_firmware()
         self.assertEqual(
             # Updates not supported info
             downgrade_firmware.getvalue().strip().split("\n")[0],
             "Downgrades not supported!!")
         return 0
     self.q._get_dom0_devices()
     downgrades = self.q._parse_downgrades(self.q.dom0_devices_info)
     for number, device in enumerate(downgrades):
         if "Name" not in device:
             continue
         if device["Name"] == "ColorHug2":
             old_version = device["Version"]
             break
     if old_version is None:
         self.fail("Test device not found")
     user_input = [str(number + 1), '1']
     with patch('builtins.input', side_effect=user_input):
         self.q.downgrade_firmware()
     self.q._get_dom0_devices()
     downgrades = self.q._parse_downgrades(self.q.dom0_devices_info)
     new_version = downgrades[number]["Version"]
     self.assertTrue(l_ver(old_version) > l_ver(new_version))
예제 #8
0
    def _parse_parameters(self, updates_dict, vm_name, choice):
        """Parses device name, url, version and SHA256 checksum of the file list.

        Keywords arguments:
        updates_dict - dictionary of updates for dom0 and usbvm
        vm_name - VM name
        choice -- number of device to be updated
        """
        self.name = updates_dict[vm_name][choice]["Name"]
        self.version = updates_dict[vm_name][choice]["Releases"][0]["Version"]
        for ver_check in updates_dict[vm_name][choice]["Releases"]:
            if l_ver(ver_check["Version"]) >= l_ver(self.version):
                self.version = ver_check["Version"]
                self.url = ver_check["Url"]
                self.sha = ver_check["Checksum"]
예제 #9
0
    def check_fwupd_version(self, usbvm=False):
        """Checks the fwupd client version and sets fwupdagent paths
        dynamicly

        Keyword arguments:
        usbvm -- usbvm support flag
        """
        version_check = 'client version:\t1.3.8'
        version_regex = re.compile(
            r'client version:\t[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}$'
        )
        cmd_version = [
            FWUPDMGR,
            "--version"
        ]
        p = subprocess.Popen(
            cmd_version,
            stdout=subprocess.PIPE
        )
        client_version = p.communicate()[0].decode().split("\n")[0]
        assert version_regex.match(client_version), (
            'Version command output has changed!!!'
        )
        if l_ver(version_check) > l_ver(client_version):
            self.fwupdagent_dom0 = FWUPDAGENT_OLD
        else:
            self.fwupdagent_dom0 = FWUPDAGENT_NEW

        if usbvm:
            cmd_version = f'"{FWUPDMGR}" --version'
            cmd_usbvm_version = [
                'qvm-run',
                '--pass-io',
                USBVM_N,
                cmd_version
            ]
            p = subprocess.Popen(
                cmd_usbvm_version,
                stdout=subprocess.PIPE
            )
            client_version = p.communicate()[0].decode().split("\n")[0]
            assert version_regex.match(client_version), (
                'Version command output has changed!!!'
            )
            if l_ver(version_check) > l_ver(client_version):
                self.fwupdagent_usbvm = FWUPDAGENT_OLD
            else:
                self.fwupdagent_usbvm = FWUPDAGENT_NEW
예제 #10
0
    def _parse_usbvm_updates(self, usbvm_devices_info):
        """Creates dictionary and list with information about updates.

        Keywords argument:
        usbvm_devices_info - gathered usbvm information
        """
        self.usbvm_updates_list = []
        if "No detected devices" in usbvm_devices_info:
            return EXIT_CODES["NOTHING_TO_DO"]
        usbvm_device_info_dict = json.loads(usbvm_devices_info)
        for device in usbvm_device_info_dict["Devices"]:
            if "Releases" in device:
                self.usbvm_updates_list.append({
                    "Name": device["Name"],
                    "Version": device["Version"],
                    "Releases": [],
                })
                current_version = device["Version"]
                for update in device["Releases"]:
                    if l_ver(update["Version"]) > current_version:
                        self.usbvm_updates_list[-1]["Releases"].append({
                            "Version":
                            update["Version"],
                            "Url":
                            update["Uri"],
                            "Checksum":
                            update["Checksum"][-1],
                            "Description":
                            update["Description"],
                        })
                if not self.usbvm_updates_list[-1]["Releases"]:
                    self.usbvm_updates_list.pop()
예제 #11
0
 def test_downgrade_firmware_dom0(self):
     old_version = None
     self.q._get_dom0_devices()
     downgrades = self.q._parse_downgrades(self.q.dom0_devices_info)
     for number, device in enumerate(downgrades):
         if "Name" not in device:
             continue
         if device["Name"] == "ColorHug2":
             old_version = device["Version"]
             break
     if old_version is None:
         self.fail("Test device not found")
     user_input = [str(number + 1), "1"]
     with patch("builtins.input", side_effect=user_input):
         self.q.downgrade_firmware()
     self.q._get_dom0_devices()
     downgrades = self.q._parse_downgrades(self.q.dom0_devices_info)
     new_version = downgrades[number]["Version"]
     self.assertGreater(l_ver(old_version), l_ver(new_version))
예제 #12
0
    def _verify_dmi(self, path, version, downgrade=False):
        """Verifies DMI tables for BIOS updates.

        Keywords arguments:
        path -- absolute path of the updates files
        version -- version of the update
        downgrade -- downgrade flag
        """
        dmi_info = self._read_dmi()
        path_metainfo = os.path.join(path, "firmware.metainfo.xml")
        tree = ET.parse(path_metainfo)
        root = tree.getroot()
        vendor = root.find("developer_name").text
        if vendor is None:
            raise ValueError("No vendor information in firmware metainfo.")
        if vendor not in dmi_info:
            raise ValueError("Wrong firmware provider.")
        if not downgrade and l_ver(version) <= l_ver(self.dmi_version):
            raise ValueError(
                f"{version} < {self.dmi_version} Downgrade not allowed")
예제 #13
0
 def test_update_firmware_dom0(self):
     old_version = None
     new_version = None
     self.q.check_fwupd_version()
     if not self.q.fwupdagent_dom0:
         update_firmware = io.StringIO()
         sys.stdout = update_firmware
         self.q.update_firmware()
         self.assertEqual(
             # Updates not supported info
             update_firmware.getvalue().strip().split("\n")[0],
             "Updates not supported!!")
         return 0
     self.q._get_dom0_updates()
     self.q._parse_dom0_updates_info(self.q.dom0_updates_info)
     for number, device in enumerate(self.q.dom0_updates_list):
         if "Name" not in device:
             continue
         if device["Name"] == "ColorHug2":
             old_version = device["Version"]
             break
     if old_version is None:
         self.fail("Test device not found")
     user_input = [str(number + 1)]
     with patch('builtins.input', side_effect=user_input):
         self.q.update_firmware()
     self.q._get_dom0_devices()
     dom0_devices_info_dict = json.loads(self.q.dom0_devices_info)
     for device in dom0_devices_info_dict["Devices"]:
         if "Name" not in device:
             continue
         if device["Name"] == "ColorHug2":
             new_version = device["Version"]
             break
     if new_version is None:
         self.fail("Test device not found")
     self.assertTrue(l_ver(old_version) < l_ver(new_version))
예제 #14
0
 def test_check_fwupd_version_dom0(self):
     self.q.check_fwupd_version()
     version_check_metadata = 'client version:\t1.4.0'
     version_check = 'client version:\t1.3.8'
     version_check_old = 'client version:\t1.2.6'
     cmd_version = ["fwupdmgr", "--version"]
     p = subprocess.Popen(cmd_version, stdout=subprocess.PIPE)
     client_version = p.communicate()[0].decode().split("\n")[0]
     if l_ver(version_check_old) > l_ver(client_version):
         self.assertIsNone(self.q.fwupdagent_dom0)
     elif l_ver(version_check) > l_ver(client_version):
         self.assertEqual(self.q.fwupdagent_dom0,
                          "/usr/libexec/fwupd/fwupdagent")
     elif l_ver(version_check_metadata) > l_ver(client_version):
         self.assertEqual(self.q.fwupdagent_dom0, "/bin/fwupdagent")
     else:
         self.assertEqual(self.q.fwupdagent_dom0, "/bin/fwupdagent")
         self.assertTrue(self.q.jcat)
예제 #15
0
 def test_check_fwupd_version_usbvm(self):
     self.q.check_fwupd_version(usbvm=True)
     version_check_metadata = 'client version:\t1.4.0'
     version_check = 'client version:\t1.3.8'
     version_check_old = 'client version:\t1.2.6'
     cmd_version = f'"{FWUPDMGR}" --version'
     cmd_usbvm_version = ['qvm-run', '--pass-io', USBVM_N, cmd_version]
     p = subprocess.Popen(cmd_usbvm_version, stdout=subprocess.PIPE)
     client_version = p.communicate()[0].decode().split("\n")[0]
     if l_ver(version_check_old) > l_ver(client_version):
         self.assertIsNone(self.q.fwupdagent_usbvm)
     elif l_ver(version_check) > l_ver(client_version):
         self.assertEqual(self.q.fwupdagent_usbvm,
                          "/usr/libexec/fwupd/fwupdagent")
     elif l_ver(version_check_metadata) > l_ver(client_version):
         self.assertEqual(self.q.fwupdagent_usbvm, "/bin/fwupdagent")
     else:
         self.assertEqual(self.q.fwupdagent_usbvm, "/bin/fwupdagent")
         self.assertTrue(self.q.jcat)
예제 #16
0
 def test_update_n_downgrade_firmware_whonix(self):
     old_version = None
     self.q.check_fwupd_version(usbvm=True)
     self.q.clean_cache(usbvm=True)
     if self.q.fwupdagent_dom0:
         self.q._get_dom0_devices()
         dom0_downgrades = self.q._parse_downgrades(
             self.q.dom0_devices_info)
     else:
         dom0_downgrades = []
     self.q._get_usbvm_devices()
     with open(FWUPD_USBVM_LOG) as usbvm_device_info:
         raw = usbvm_device_info.read()
         downgrades = self.q._parse_downgrades(raw)
         for number, device in enumerate(downgrades):
             if "Name" not in device:
                 continue
             if device["Name"] == "ColorHug2":
                 old_version = device["Version"]
                 break
     if old_version is None:
         self.fail("Test device not found")
     user_input = [str(number + 1 + len(dom0_downgrades)), '1']
     with patch('builtins.input', side_effect=user_input):
         self.q.downgrade_firmware(usbvm=True, whonix=True)
     self.q._get_usbvm_devices()
     with open(FWUPD_USBVM_LOG) as usbvm_device_info:
         raw = usbvm_device_info.read()
         downgrades = self.q._parse_downgrades(raw)
     new_version = downgrades[number]["Version"]
     self.assertTrue(l_ver(old_version) > l_ver(new_version))
     old_version = None
     new_version = None
     self.q.check_fwupd_version(usbvm=True)
     if self.q.fwupdagent_dom0:
         self.q._get_dom0_updates()
         self.q._parse_dom0_updates_info(self.q.dom0_updates_info)
     else:
         self.q.dom0_updates_list = []
     self.q._get_usbvm_devices()
     with open(FWUPD_USBVM_LOG) as usbvm_device_info:
         raw = usbvm_device_info.read()
         self.q._parse_usbvm_updates(raw)
         for number, device in enumerate(self.q.usbvm_updates_list):
             if "Name" not in device:
                 continue
             if device["Name"] == "ColorHug2":
                 old_version = device["Version"]
                 break
     if old_version is None:
         self.fail("Test device not found")
     user_input = [str(number + 1 + len(self.q.dom0_updates_list)), '1']
     with patch('builtins.input', side_effect=user_input):
         self.q.update_firmware(usbvm=True, whonix=True)
     self.q._get_usbvm_devices()
     with open(FWUPD_USBVM_LOG) as usbvm_device_info:
         raw = usbvm_device_info.read()
         usbvm_devices_info_dict = json.loads(raw)
     for device in usbvm_devices_info_dict["Devices"]:
         if "Name" not in device:
             continue
         if device["Name"] == "ColorHug2":
             new_version = device["Version"]
             break
     if new_version is None:
         self.fail("Test device not found")
     self.assertTrue(l_ver(old_version) < l_ver(new_version))