-
Notifications
You must be signed in to change notification settings - Fork 22
Backup and restore of Passwords #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AdityaMitra5102
wants to merge
18
commits into
Nitrokey:main
Choose a base branch
from
AdityaMitra5102:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5892baa
Backup and restore
AdityaMitra5102 12f6723
Nitrokey touch prompt
AdityaMitra5102 0115205
Remove Backup, Restore buttons from passkey window
AdityaMitra5102 76dd671
Fix static typing and code style issues
AdityaMitra5102 6a181be
Fix typing, format issues
AdityaMitra5102 3d04e0a
Fixed imports
AdityaMitra5102 ca5b1b4
Icons added
AdityaMitra5102 a9ffaee
Updated and moved logic to SDK
AdityaMitra5102 8dd143d
Updated to use dicts directly instead of CXFPayload objects for backu…
AdityaMitra5102 e8af392
Remove references removed from SDK
AdityaMitra5102 27be8ad
Just for testing
AdityaMitra5102 3d2fc8b
Fix backup restore UI
AdityaMitra5102 764a089
address comments from Robin
AdityaMitra5102 f376ba8
Pin protected passwords visible without admin. Issue 419
AdityaMitra5102 88ee979
UI Changes done as per last comment
AdityaMitra5102 ce1011e
Revert changes to make password protected lists visible without admin
AdityaMitra5102 93e343d
Handle Issue 4444
AdityaMitra5102 eee7dac
Revert 444 commit because it is shifted to a different PR
AdityaMitra5102 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| from enum import Enum | ||
| from typing import Callable, List, Optional | ||
|
|
||
| from PySide6.QtGui import QGuiApplication, QIcon | ||
| from PySide6.QtWidgets import ( | ||
| QCheckBox, | ||
| QDialog, | ||
| QHBoxLayout, | ||
| QLabel, | ||
| QLineEdit, | ||
| QListWidget, | ||
| QPushButton, | ||
| QStatusBar, | ||
| QToolButton, | ||
| QVBoxLayout, | ||
| QWidget, | ||
| ) | ||
|
|
||
|
|
||
| class BackupRestoreAction(str, Enum): | ||
| BACKUP = "backup" | ||
| RESTORE = "restore" | ||
|
|
||
|
|
||
| class BackupRestoreUi(QDialog): | ||
| def __init__( | ||
| self, name: BackupRestoreAction, title: str, icon: QIcon, parent: Optional[QWidget] = None | ||
| ) -> None: | ||
| super().__init__(parent) | ||
|
|
||
| self.name = name | ||
| self.setWindowTitle(name.capitalize()) | ||
|
|
||
| self.action_edit = QLabel(f"Action: {title}") | ||
|
|
||
| action_layout = QHBoxLayout() | ||
| action_layout.addWidget(self.action_edit) | ||
|
|
||
| self.cleartext_checkbox = QCheckBox("Cleartext") | ||
| self.cleartext_checkbox.setToolTip( | ||
| "This option disables encryption of the generated backup and is discouraged. Only use for interoperability with other password managers." | ||
| ) | ||
| self.cleartext_checkbox.setVisible(name == BackupRestoreAction.BACKUP) | ||
|
|
||
| self.passphrase_edit = QLineEdit() | ||
| self.passphrase_edit.setToolTip( | ||
| "Passphrase is automatically created during an encrypted backup." | ||
| ) | ||
| self.passphrase_edit.setReadOnly(name == BackupRestoreAction.BACKUP) | ||
|
|
||
| self.copy_passphrase_button = QToolButton() | ||
| self.copy_passphrase_button.setIcon(icon) | ||
| self.copy_passphrase_button.setToolTip("Copy passphrase") | ||
|
|
||
| self.begin_button = QPushButton("Begin") | ||
|
|
||
| passphrase_layout = QHBoxLayout() | ||
| passphrase_layout.setContentsMargins(0, 0, 0, 0) | ||
| passphrase_layout.addWidget(self.passphrase_edit) | ||
| if self.name == BackupRestoreAction.BACKUP: | ||
| passphrase_layout.addWidget(self.copy_passphrase_button) | ||
|
|
||
| middle_layout = QHBoxLayout() | ||
| middle_layout.addWidget(self.cleartext_checkbox) | ||
| middle_layout.addStretch(1) | ||
| middle_layout.addWidget(QLabel("Passphrase")) | ||
| middle_layout.addLayout(passphrase_layout, 1) | ||
| middle_layout.addWidget(self.begin_button) | ||
|
|
||
| self.copy_passphrase_button.clicked.connect(self.copy_passphrase) | ||
|
|
||
| self.successful_list = QListWidget() | ||
| self.failed_list = QListWidget() | ||
| self.skipped_list = QListWidget() | ||
|
|
||
| self.failed_name = ( | ||
| "Not passwords" if name == BackupRestoreAction.BACKUP else "Already exists" | ||
| ) | ||
|
|
||
| self.successful_label = QLabel("Successful (0)") | ||
| self.successful_label.setToolTip("Operation on these credentials completed successfully") | ||
|
|
||
| self.failed_label = QLabel(f"{self.failed_name} (0)") | ||
| self.failed_label.setToolTip( | ||
| "Credentials without a password (for example OTP only) are skipped during the backup as they cannot be extracted from the device." | ||
| if name == BackupRestoreAction.BACKUP | ||
| else "Credentials not imported because a credential with same label already exists on the device" | ||
| ) | ||
|
|
||
| self.skipped_label = QLabel("Skipped (0)") | ||
| self.skipped_label.setToolTip( | ||
| "Credentials are skipped if they are PIN protected but PIN is not supplied." | ||
| ) | ||
|
|
||
| lists_layout = QHBoxLayout() | ||
| for label, widget in ( | ||
| (self.successful_label, self.successful_list), | ||
| (self.failed_label, self.failed_list), | ||
| (self.skipped_label, self.skipped_list), | ||
| ): | ||
| column = QVBoxLayout() | ||
| column.addWidget(label) | ||
| column.addWidget(widget) | ||
| lists_layout.addLayout(column) | ||
|
|
||
| self.status_edit = QStatusBar() | ||
| # self.status_edit.setReadOnly(True) | ||
|
|
||
| status_layout = QHBoxLayout() | ||
| status_layout.addWidget(QLabel("Status")) | ||
| status_layout.addWidget(self.status_edit) | ||
|
|
||
| layout = QVBoxLayout() | ||
| layout.addLayout(action_layout) | ||
| layout.addSpacing(16) | ||
| layout.addLayout(middle_layout) | ||
| layout.addLayout(lists_layout) | ||
| layout.addLayout(status_layout) | ||
| self.setLayout(layout) | ||
|
|
||
| self.resize(900, 520) | ||
|
|
||
| def copy_passphrase(self) -> None: | ||
| if self.passphrase_edit.text() != "": | ||
| QGuiApplication.clipboard().setText(self.passphrase_edit.text()) | ||
| self.update_status("Passphrase copied!") | ||
| else: | ||
| self.update_status("Nothing to copy!") | ||
|
|
||
| def update_fields( | ||
| self, success_list: List[bytes], failed_list: List[bytes], skipped_list: List[bytes] | ||
| ) -> None: | ||
| self.successful_list.clear() | ||
| self.failed_list.clear() | ||
| self.skipped_list.clear() | ||
|
|
||
| for item in success_list: | ||
| self.successful_list.addItem(item.decode("utf-8", errors="ignore")) | ||
|
|
||
| for item in failed_list: | ||
| self.failed_list.addItem(item.decode("utf-8", errors="ignore")) | ||
|
|
||
| for item in skipped_list: | ||
| self.skipped_list.addItem(item.decode("utf-8", errors="ignore")) | ||
|
|
||
| self.successful_label.setText(f"Successful ({len(success_list)})") | ||
| self.failed_label.setText(f"{self.failed_name} ({len(failed_list)})") | ||
| self.skipped_label.setText(f"Skipped ({len(skipped_list)})") | ||
|
|
||
| def update_status(self, status: str) -> None: | ||
| self.status_edit.showMessage(status) | ||
|
|
||
| def update_passphrase(self, passphrase: str) -> None: | ||
| self.passphrase_edit.setText(passphrase) | ||
|
|
||
| def begin(self, callback: Callable[[bool, str, BackupRestoreAction], None]) -> None: | ||
| def on_clicked() -> None: | ||
| callback(self.cleartext_checkbox.isChecked(), self.passphrase_edit.text(), self.name) | ||
|
|
||
| self.begin_button.clicked.connect(on_clicked) | ||
|
|
||
|
|
||
| def open_backup_restore_ui( | ||
| action: BackupRestoreAction, title: str, icon: QIcon, parent: Optional[QWidget] = None | ||
| ) -> BackupRestoreUi: | ||
| ui = BackupRestoreUi(action, title, icon, parent) | ||
| ui.show() | ||
| return ui | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be useful to add tooltips to these fields that describe:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed is not shown as failed. During backup, failed means it is not a password credential. During restore failed means another credential with same label already exists on the key
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleartext and passphrase tooltips added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. For us it is clear what Not passwords means but I think without context it could be confusing. That’s why I’d also add a tooltip here, something like: Credentials without a password (for example OTP only) are skipped during the backup as they cannot be extracted from the device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed