Exemplo n.º 1
0
    def _do_ensure_auth(self, key, window):
        if key is not None:
            try:
                self.authenticate(key)
                return
            except ValueError as e:
                QtGui.QMessageBox.warning(window, m.error, str(e))

        key, status = get_text(window, m.enter_key, m.key_label)
        if not status:
            raise ValueError('Key entry aborted!')
        self._do_ensure_auth(key, window)
Exemplo n.º 2
0
    def _do_ensure_auth(self, key, window):
        if key is not None:
            try:
                self.authenticate(key)
                return
            except ValueError as e:
                QtGui.QMessageBox.warning(window, m.error, str(e))

        key, status = get_text(window, m.enter_key, m.key_label)
        if not status:
            raise ValueError('Key entry aborted!')
        self._do_ensure_auth(key, window)
Exemplo n.º 3
0
    def _import_file(self, controller, release):

        fn, fn_filter = QtGui.QFileDialog.getOpenFileName(
            self, m.import_from_file, filter=FILE_FILTER)
        if not fn:
            return

        func, needs_password, is_key = import_file(controller, self._slot, fn)
        if func is None:
            QtGui.QMessageBox.warning(self, m.error, m.unsupported_file)
            return
        if is_key:
            dialog = UsagePolicyDialog(controller, self._slot, self)
            if dialog.has_content and dialog.exec_():
                func = partial(func, pin_policy=dialog.pin_policy,
                               touch_policy=dialog.touch_policy)
                settings[SETTINGS.TOUCH_POLICY] = dialog.touch_policy

        if needs_password:
            password, status = get_text(
                self, m.enter_file_password, m.password_label,
                QtGui.QLineEdit.Password)
            if not status:
                return
            func = partial(func, password=password)

        try:
            if not controller.poll():
                controller.reconnect()
            controller.ensure_authenticated()
        except Exception as e:
            QtGui.QMessageBox.warning(self, m.error, str(e))

        # User confirmation for overwriting slot data
        if self._slot in controller.certs:
            res = QtGui.QMessageBox.warning(
                self,
                m.overwrite_slot_warning,
                m.overwrite_slot_warning_desc % self._slot,
                QtGui.QMessageBox.Ok,
                QtGui.QMessageBox.Cancel)
            if res == QtGui.QMessageBox.Cancel:
                return

        try:
            worker = QtCore.QCoreApplication.instance().worker
            worker.post(m.importing_file, func, partial(
                self._import_file_callback, controller, release), True)
        except (DeviceGoneError, PivError, ValueError) as e:
            QtGui.QMessageBox.warning(self, m.error, str(e))
Exemplo n.º 4
0
    def _import_file(self, controller, release):
        res = QtGui.QMessageBox.warning(
            self, m.import_from_file,
            m.import_from_file_warning_1 % self._slot, QtGui.QMessageBox.Ok,
            QtGui.QMessageBox.Cancel)
        if res != QtGui.QMessageBox.Ok:
            return

        fn, fn_filter = QtGui.QFileDialog.getOpenFileName(self,
                                                          m.import_from_file,
                                                          filter=FILE_FILTER)
        if not fn:
            return

        func, needs_password, is_key = import_file(controller, self._slot, fn)
        if func is None:
            QtGui.QMessageBox.warning(self, m.error, m.unsupported_file)
            return
        if is_key:
            dialog = UsagePolicyDialog(controller, self._slot, self)
            if dialog.has_content and dialog.exec_():
                func = partial(func,
                               pin_policy=dialog.pin_policy,
                               touch_policy=dialog.touch_policy)
                settings[SETTINGS.TOUCH_POLICY] = dialog.touch_policy

        if needs_password:
            password, status = get_text(self, m.enter_file_password,
                                        m.password_label,
                                        QtGui.QLineEdit.Password)
            if not status:
                return
            func = partial(func, password=password)

        try:
            if not controller.poll():
                controller.reconnect()

            controller.ensure_authenticated()
            worker = QtCore.QCoreApplication.instance().worker
            worker.post(
                m.importing_file, func,
                partial(self._import_file_callback, controller, release), True)
        except (DeviceGoneError, PivError, ValueError) as e:
            QtGui.QMessageBox.warning(self, m.error, str(e))
Exemplo n.º 5
0
    def ensure_pin(self, pin=None, window=None):
        if window is None:
            window = get_active_window()

        if pin is not None:
            try:
                self.verify_pin(pin)
                return pin
            except WrongPinError as e:
                if e.blocked:
                    raise
                QtGui.QMessageBox.warning(window, m.error, str(e))
            except ValueError as e:
                QtGui.QMessageBox.warning(window, m.error, str(e))

        pin, status = get_text(
            window, m.enter_pin, m.pin_label, QtGui.QLineEdit.Password)
        if not status:
            raise ValueError('PIN entry aborted!')
        return self.ensure_pin(pin)
Exemplo n.º 6
0
    def ensure_pin(self, pin=None, window=None):
        if window is None:
            window = get_active_window()

        if pin is not None:
            try:
                self.verify_pin(pin)
                return pin
            except WrongPinError as e:
                if e.blocked:
                    raise
                QtGui.QMessageBox.warning(window, m.error, str(e))
            except ValueError as e:
                QtGui.QMessageBox.warning(window, m.error, str(e))

        pin, status = get_text(window, m.enter_pin, m.pin_label,
                               QtGui.QLineEdit.Password)
        if not status:
            raise ValueError('PIN entry aborted!')
        return self.ensure_pin(pin, window)