Пример #1
0
    def wrapper(**kwargs):
        config = kwargs["config"]
        password = kwargs["password"]
        device_slughash = kwargs.pop("device")

        all_available_devices = list_available_devices(config.config_dir)
        devices = []
        for device in all_available_devices:
            if device.slughash.startswith(device_slughash):
                devices.append(device)

        if not devices:
            raise SystemExit(
                f"Device `{device_slughash}` not found, available devices:\n"
                f"{format_available_devices(all_available_devices)}"
            )
        elif len(devices) > 1:
            raise SystemExit(
                f"Multiple devices found for `{device_slughash}`:\n"
                f"{format_available_devices(devices)}"
            )

        try:
            if password is None:
                password = click.prompt("password", hide_input=True)
            device = load_device_with_password(devices[0].key_file_path, password)

        except LocalDeviceError as exc:
            raise SystemExit(f"Cannot load device {device_slughash}: {exc}")

        kwargs["device"] = device
        return fn(**kwargs)
Пример #2
0
async def main(config_dir, complex_mode, user_display, password):

    # Config
    configure_logging(LOG_LEVEL)
    config_dir = config_dir or get_default_config_dir(os.environ)
    config = load_config(config_dir)
    devices = list_available_devices(config_dir)
    key_file = next(
        device.key_file_path for device in devices if device.user_display == user_display
    )
    print(f"Key file: {key_file}")
    device = load_device_with_password(key_file, password)

    # Log in
    async with logged_client_factory(config, device) as client:

        # Get workspace
        user_manifest = client.user_fs.get_user_manifest()
        workspace_entry = user_manifest.workspaces[0]
        workspace = client.user_fs.get_workspace(workspace_entry.id)

        # await make_workspace_dir_inconsistent(device, workspace, "/bar")
        if complex_mode:
            await make_workspace_dir_complex_versions(device, workspace, "/foo")
        else:
            await make_workspace_dir_simple_versions(device, workspace, "/foo")
Пример #3
0
    def show_window(self, skip_dialogs=False, invitation_link=""):
        self.show()
        try:
            if not self.restoreGeometry(self.config.gui_geometry):
                self.resize_standard()
        except TypeError:
            self.resize_standard()

        QCoreApplication.processEvents()

        # Used with the --diagnose option
        if skip_dialogs:
            return

        # At the very first launch
        if self.config.gui_first_launch:
            self.event_bus.send(
                ClientEvent.GUI_CONFIG_CHANGED,
                gui_first_launch=False,
                gui_last_version=GUARDATA_VERSION,
            )

        # For each guardata update
        if self.config.gui_last_version and self.config.gui_last_version != GUARDATA_VERSION:

            # Acknowledge the changes
            self.event_bus.send(ClientEvent.GUI_CONFIG_CHANGED,
                                gui_last_version=GUARDATA_VERSION)

        devices = list_available_devices(self.config.config_dir)
        if not len(devices) and not invitation_link and platform != "darwin":
            # Add some refresh of async sleep
            # ELse should start once the main window is fully painted (catch ready event)
            self.show_top()

            def _on_bootstrap_question_finished(return_code, answer):
                if not return_code:
                    return
                if answer == _("ACTION_NO_DEVICE_JOIN_ORGANIZATION"):
                    self._on_join_org_clicked()
                elif answer == _("ACTION_NO_DEVICE_CREATE_ORGANIZATION"):
                    self._on_create_org_clicked()

            ask_question(
                self,
                _("TEXT_KICKSTART_GUARDATA_WHAT_TO_DO_TITLE"),
                _("TEXT_KICKSTART_GUARDATA_WHAT_TO_DO_INSTRUCTIONS"),
                [
                    _("ACTION_NO_DEVICE_CREATE_ORGANIZATION"),
                    _("ACTION_NO_DEVICE_JOIN_ORGANIZATION"),
                ],
                on_finished=_on_bootstrap_question_finished,
                radio_mode=True,
            )
Пример #4
0
 def _find_device_from_addr(self, action_addr, display_error=False):
     device = None
     for available_device in list_available_devices(self.config.config_dir):
         if available_device.organization_id == action_addr.organization_id:
             device = available_device
             break
     if device is None:
         show_error(
             self,
             _("TEXT_FILE_LINK_NOT_IN_ORG_organization").format(
                 organization=action_addr.organization_id),
         )
     return device
Пример #5
0
def test_list_devices_support_legacy_file_with_meaningful_name(config_dir):
    # Legacy path might exceed the 256 characters limit in some cases (see issue #1356)
    # So we use the `\\?\` workaround: https://stackoverflow.com/a/57502760/2846140
    if os.name == "nt":
        config_dir = Path("\\\\?\\" + str(config_dir.resolve()))

    # Device information
    user_id = uuid4().hex
    device_name = uuid4().hex
    organization_id = "Org"
    rvk_hash = (uuid4().hex)[:10]
    device_id = f"{user_id}@{device_name}"
    slug = f"{rvk_hash}#{organization_id}#{device_id}"
    human_label = "Billy Mc BillFace"
    human_email = "*****@*****.**"
    device_label = "My device"

    # Craft file data without the user_id, organization_id and
    # root_verify_key_hash fields
    key_file_data = packb({
        "type":
        "password",
        "salt":
        b"12345",
        "ciphertext":
        b"whatever",
        "human_handle": (human_email.encode(), human_label.encode()),
        "device_label":
        device_label.encode(),
    })

    key_file_path = get_devices_dir(config_dir) / slug / f"{slug}.keys"
    key_file_path.parent.mkdir(parents=True)
    key_file_path.write_bytes(key_file_data)

    devices = list_available_devices(config_dir)
    expected_device = AvailableDevice(
        key_file_path=key_file_path,
        organization_id=OrganizationID(organization_id),
        device_id=DeviceID(device_id),
        human_handle=HumanHandle(human_email, human_label),
        device_label=device_label,
        root_verify_key_hash=rvk_hash,
    )
    assert devices == [expected_device]
Пример #6
0
def test_list_devices(organization_factory, local_device_factory, config_dir):
    org1 = organization_factory("org1")
    org2 = organization_factory("org2")

    o1d11 = local_device_factory("d1@1", org1)
    o1d12 = local_device_factory("d1@2", org1)
    o1d21 = local_device_factory("d2@1", org1)

    o2d11 = local_device_factory("d1@1", org2, has_human_handle=False)
    o2d12 = local_device_factory("d1@2", org2, has_device_label=False)
    o2d21 = local_device_factory("d2@1",
                                 org2,
                                 has_human_handle=False,
                                 has_device_label=False)

    for device in [o1d11, o1d12, o1d21]:
        save_device_with_password(config_dir, device, "S3Cr37")

    for device in [o2d11, o2d12, o2d21]:
        save_device_with_password(config_dir, device, "secret")

    # Also add dummy stuff that should be ignored
    device_dir = config_dir / "devices"
    (device_dir / "bad1").touch()
    (device_dir / "373955f566#corp#bob@laptop").mkdir()
    dummy_slug = "a54ed6df3a#corp#alice@laptop"
    (device_dir / dummy_slug).mkdir()
    (device_dir / dummy_slug / f"{dummy_slug}.keys").write_bytes(b"dummy")

    devices = list_available_devices(config_dir)

    expected_devices = {
        AvailableDevice(
            key_file_path=get_key_file(config_dir, d),
            organization_id=d.organization_id,
            device_id=d.device_id,
            human_handle=d.human_handle,
            device_label=d.device_label,
            root_verify_key_hash=d.root_verify_key_hash,
        )
        for d in [o1d11, o1d12, o1d21, o2d11, o2d12, o2d21]
    }
    assert set(devices) == expected_devices
Пример #7
0
def test_list_devices_support_legacy_file_without_labels(config_dir):
    # Craft file data without the labels fields
    key_file_data = packb({
        "type": "password",
        "salt": b"12345",
        "ciphertext": b"whatever"
    })
    slug = "9d84fbd57a#Org#Zack@PC1"
    key_file_path = fix_dir(
        get_devices_dir(config_dir) / slug / f"{slug}.keys")
    key_file_path.parent.mkdir(parents=True)
    key_file_path.write_bytes(key_file_data)

    devices = list_available_devices(config_dir)
    expected_device = AvailableDevice(
        key_file_path=key_file_path,
        organization_id=OrganizationID("Org"),
        device_id=DeviceID("Zack@PC1"),
        human_handle=None,
        device_label=None,
        root_verify_key_hash="9d84fbd57a",
    )
    assert devices == [expected_device]
Пример #8
0
 def reload_devices(self):
     self._clear_widget()
     devices_all = list_available_devices(self.config.config_dir)
     devices = [
         device
         for device in devices_all if not guardataApp.is_device_connected(
             device.organization_id, device.device_id)
     ]
     n_devices = len(devices)
     if n_devices < 1:
         no_device_widget = LoginNoDevicesWidget()
         no_device_widget.create_organization_clicked.connect(
             self.create_organization_clicked.emit)
         no_device_widget.join_organization_clicked.connect(
             self.join_organization_clicked.emit)
         self.widget.layout().addWidget(no_device_widget)
         no_device_widget.setFocus()
     elif n_devices == 1:
         self._on_account_clicked(devices[0], hide_back=True)
     else:
         accounts_widget = LoginAccountsWidget(devices)
         accounts_widget.account_clicked.connect(self._on_account_clicked)
         self.widget.layout().addWidget(accounts_widget)
         accounts_widget.setFocus()
Пример #9
0
def test_list_no_devices(path_exists, config_dir):
    config_dir = config_dir if path_exists else fix_dir(config_dir / "dummy")
    devices = list_available_devices(config_dir)
    assert not devices
Пример #10
0
def test_run_testenv(run_testenv):
    available_devices = list_available_devices(run_testenv.config_dir)
    devices = [(d.human_handle.label, d.device_label) for d in available_devices]
    assert sorted(devices) == [("Alice", "laptop"), ("Alice", "pc"), ("Bob", "laptop")]