diff --git a/src/python/backend.py b/src/python/backend.py index 2286ebce..df105e41 100644 --- a/src/python/backend.py +++ b/src/python/backend.py @@ -141,29 +141,6 @@ class Backend: return nio.Api.mxc_to_http(mxc) - @staticmethod - async def check_exported_keys_passphrase(file_path: str, passphrase: str, - ) -> Union[bool, Tuple[str, bool]]: - """Check if the exported keys file can be decrypted with passphrase. - - Returns True on success, False is the passphrase is invalid, or - an (error_message, error_is_translated) tuple if another error occured. - """ - - try: - nio.crypto.key_export.decrypt_and_read(file_path, passphrase) - return True - - except OSError as err: # XXX raise - return (f"{file_path}: {err.strerror}", True) - - except ValueError as err: # XXX raise - if str(err).startswith("HMAC check failed"): - return False - - return (str(err), False) - - async def load_settings(self) -> tuple: from .config_files import Theme settings = await self.ui_settings.read() diff --git a/src/qml/Dialogs/ExportKeys.qml b/src/qml/Dialogs/ExportKeys.qml index 0ea34e42..d2fcf12b 100644 --- a/src/qml/Dialogs/ExportKeys.qml +++ b/src/qml/Dialogs/ExportKeys.qml @@ -12,6 +12,8 @@ HFileDialogOpener { } + // This is used for the LogoutPopup to know when the export is done + // so it can close signal done() diff --git a/src/qml/Dialogs/ImportKeys.qml b/src/qml/Dialogs/ImportKeys.qml index cd08f3b8..be9ed8c9 100644 --- a/src/qml/Dialogs/ImportKeys.qml +++ b/src/qml/Dialogs/ImportKeys.qml @@ -11,24 +11,10 @@ HFileDialogOpener { } - signal done() - - property string userId: "" property bool importing: false - function importKeys(file, passphrase) { - importing = true - - let path = file.toString().replace(/^file:\/\//, "") - py.callClientCoro(userId, "import_keys", [path, passphrase], () => { - importing = false - done() - }) - } - - PasswordPopup { id: importPasswordPopup details.text: qsTr( @@ -36,16 +22,38 @@ HFileDialogOpener { ) okText: qsTr("Import") - onAcceptedPasswordChanged: importKeys(file, acceptedPassword) property url file: "" + function verifyPassword(pass, callback) { - py.callCoro( - "check_exported_keys_passphrase", - [file.toString().replace(/^file:\/\//, ""), pass], - callback - ) + importing = true + let path = file.toString().replace(/^file:\/\//, "") + + py.callClientCoro(userId, "import_keys", [path, pass], () => { + importing = false + callback(true) + + }, (type, args) => { + callback( + type === "EncryptionError" ? + false : + + type === "ValueError" ? + qsTr("Invalid file format") : + + type === "FileNotFoundError" ? + qsTr("This file doesn't exist") : + + type === "IsADirectoryError" ? + qsTr("A folder was given, expecting a file") : + + type === "PermissionError" ? + qsTr("No permission to read this file") : + + qsTr("Unknown error: %1 - %2").arg(type).arg(args) + ) + }) } } } diff --git a/src/qml/Popups/PasswordPopup.qml b/src/qml/Popups/PasswordPopup.qml index bc7cf1b3..9cb38d84 100644 --- a/src/qml/Popups/PasswordPopup.qml +++ b/src/qml/Popups/PasswordPopup.qml @@ -25,8 +25,8 @@ BoxPopup { function verifyPassword(pass, callback) { // Can be reimplemented when using this component. - // Pass to the callback true on success, false on invalid password, or - // a [error message, translated] array for any other error. + // Pass to the callback true on success, false on invalid password, + // or a custom error message string. callback(true) } @@ -46,8 +46,7 @@ BoxPopup { } else if (result === false) { passwordValid = false } else { - let [msg, translated] = result - errorMessage.text = translated ? msg : qsTr(msg) + errorMessage.text = result } button.loading = false