From 9fcf468fe5b6f30ad78e63e6f8fcfde437168632 Mon Sep 17 00:00:00 2001 From: Elias Bonnici Date: Wed, 20 Dec 2023 14:18:59 +0100 Subject: [PATCH] Add specific error status for FIDO key mismatch. --- helper/helper/fido.py | 9 ++++++++- lib/fido/views/reset_dialog.dart | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/helper/helper/fido.py b/helper/helper/fido.py index 1b593478..6750ade3 100644 --- a/helper/helper/fido.py +++ b/helper/helper/fido.py @@ -55,6 +55,13 @@ class InactivityException(RpcException): ) +class KeyMismatchException(RpcException): + def __init__(self): + super().__init__( + "key-mismatch", "Re-inserted YubiKey does not match initial device" + ) + + def _ctap_id(ctap): return (ctap.info.aaguid, ctap.info.firmware_version) @@ -171,7 +178,7 @@ class Ctap2Node(RpcNode): logger.debug("Performing reset...") self.ctap = Ctap2(connection) if target != _ctap_id(self.ctap): - raise ValueError("Re-inserted YubiKey does not match initial device") + raise KeyMismatchException() try: self.ctap.reset(event=event) except CtapError as e: diff --git a/lib/fido/views/reset_dialog.dart b/lib/fido/views/reset_dialog.dart index 8d8f1b07..c108dfed 100755 --- a/lib/fido/views/reset_dialog.dart +++ b/lib/fido/views/reset_dialog.dart @@ -99,7 +99,7 @@ class _ResetDialogState extends ConsumerState { if (e is RpcError) { if (e.status == 'connection-error') { errorMessage = l10n.l_failed_connecting_to_fido; - } else if (e.status == 'invalid-command') { + } else if (e.status == 'key-mismatch') { errorMessage = l10n.l_wrong_inserted_yk_error; } else if (e.status == 'user-action-timeout') { errorMessage = l10n.l_user_action_timeout_error;