diff --git a/helper/helper/fido.py b/helper/helper/fido.py index cf2a41fa..6750ade3 100644 --- a/helper/helper/fido.py +++ b/helper/helper/fido.py @@ -47,6 +47,21 @@ class PinValidationException(RpcException): ) +class InactivityException(RpcException): + def __init__(self): + super().__init__( + "user-action-timeout", + "Failed to add fingerprint due to user inactivity.", + ) + + +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) @@ -163,8 +178,12 @@ 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") - self.ctap.reset(event=event) + raise KeyMismatchException() + try: + self.ctap.reset(event=event) + except CtapError as e: + if e.code == CtapError.ERR.USER_ACTION_TIMEOUT: + raise InactivityException() self._info = self.ctap.get_info() self._auth_blocked = False self._token = None @@ -340,6 +359,9 @@ class FingerprintsNode(RpcNode): signal("capture", dict(remaining=enroller.remaining)) except CaptureError as e: signal("capture-error", dict(code=e.code)) + except CtapError as e: + if e.code == CtapError.ERR.USER_ACTION_TIMEOUT: + raise InactivityException() if name: self.bio.set_name(template_id, name) self._templates[template_id] = name diff --git a/lib/fido/views/add_fingerprint_dialog.dart b/lib/fido/views/add_fingerprint_dialog.dart index 26625fd9..138a7d39 100755 --- a/lib/fido/views/add_fingerprint_dialog.dart +++ b/lib/fido/views/add_fingerprint_dialog.dart @@ -113,16 +113,23 @@ class _AddFingerprintDialogState extends ConsumerState }, onError: (error, stacktrace) { _log.error('Error adding fingerprint', error, stacktrace); Navigator.of(context).pop(); + final l10n = AppLocalizations.of(context)!; final String errorMessage; // TODO: Make this cleaner than importing desktop specific RpcError. if (error is RpcError) { - errorMessage = error.message; + if (error.status == 'user-action-timeout') { + errorMessage = l10n.l_user_action_timeout_error; + } else if (error.status == 'connection-error') { + errorMessage = l10n.l_failed_connecting_to_fido; + } else { + errorMessage = error.message; + } } else { errorMessage = error.toString(); } showMessage( context, - 'Error adding fingerprint: $errorMessage', + l10n.l_adding_fingerprint_failed(errorMessage), duration: const Duration(seconds: 4), ); }); diff --git a/lib/fido/views/reset_dialog.dart b/lib/fido/views/reset_dialog.dart index 9b27f687..c108dfed 100755 --- a/lib/fido/views/reset_dialog.dart +++ b/lib/fido/views/reset_dialog.dart @@ -97,7 +97,15 @@ class _ResetDialogState extends ConsumerState { final String errorMessage; // TODO: Make this cleaner than importing desktop specific RpcError. if (e is RpcError) { - errorMessage = e.message; + if (e.status == 'connection-error') { + errorMessage = l10n.l_failed_connecting_to_fido; + } 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; + } else { + errorMessage = e.message; + } } else { errorMessage = e.toString(); } diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index ee786cdc..91a0187d 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -406,6 +406,10 @@ "s_fingerprints": "Fingerabdrücke", "l_fingerprint_captured": "Fingerabdruck erfolgreich aufgenommen!", "s_fingerprint_added": "Fingerabdruck hinzugefügt", + "l_adding_fingerprint_failed": null, + "@l_adding_fingerprint_failed": { + "placeholders": {} + }, "l_setting_name_failed": "Fehler beim Setzen des Namens: {message}", "@l_setting_name_failed": { "placeholders": { @@ -441,6 +445,11 @@ "p_press_fingerprint_begin": "Drücken Sie Ihren Finger gegen den YubiKey um zu beginnen.", "p_will_change_label_fp": "Das ändert die Beschriftung des Fingerabdrucks.", + "@_fido_errors": {}, + "l_user_action_timeout_error": null, + "l_wrong_inserted_yk_error": null, + "l_failed_connecting_to_fido": null, + "@_certificates": {}, "s_certificate": null, "s_csr": null, diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 9d63a036..4c178a2e 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -406,6 +406,10 @@ "s_fingerprints": "Fingerprints", "l_fingerprint_captured": "Fingerprint captured successfully!", "s_fingerprint_added": "Fingerprint added", + "l_adding_fingerprint_failed": "Error adding fingerprint: {message}", + "@l_adding_fingerprint_failed": { + "placeholders": {} + }, "l_setting_name_failed": "Error setting name: {message}", "@l_setting_name_failed": { "placeholders": { @@ -441,6 +445,11 @@ "p_press_fingerprint_begin": "Press your finger against the YubiKey to begin.", "p_will_change_label_fp": "This will change the label of the fingerprint.", + "@_fido_errors": {}, + "l_user_action_timeout_error": "Failed due to user inactivity", + "l_wrong_inserted_yk_error": "Re-inserted YubiKey does not match initial device", + "l_failed_connecting_to_fido": "Failed connecting to FIDO interface", + "@_certificates": {}, "s_certificate": "Certificate", "s_csr": "CSR", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index fb0439d5..eaa70c80 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -406,6 +406,10 @@ "s_fingerprints": "Empreintes", "l_fingerprint_captured": "Empreinte capturée avec succès!", "s_fingerprint_added": "Empreinte ajoutée", + "l_adding_fingerprint_failed": null, + "@l_adding_fingerprint_failed": { + "placeholders": {} + }, "l_setting_name_failed": "Erreur lors de l'ajout du nom: {message}", "@l_setting_name_failed": { "placeholders": { @@ -441,6 +445,11 @@ "p_press_fingerprint_begin": "Posez votre doigt sur votre YubiKey pour commencer.", "p_will_change_label_fp": "Cette action changera la description de votre empreinte.", + "@_fido_errors": {}, + "l_user_action_timeout_error": null, + "l_wrong_inserted_yk_error": null, + "l_failed_connecting_to_fido": null, + "@_certificates": {}, "s_certificate": "Certificat", "s_csr": "CSR", diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index 53595019..c40b1f61 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -406,6 +406,10 @@ "s_fingerprints": "指紋", "l_fingerprint_captured": "指紋の取得に成功しました!", "s_fingerprint_added": "指紋が追加されました", + "l_adding_fingerprint_failed": null, + "@l_adding_fingerprint_failed": { + "placeholders": {} + }, "l_setting_name_failed": "名前設定時名エラー:{message}", "@l_setting_name_failed": { "placeholders": { @@ -441,6 +445,11 @@ "p_press_fingerprint_begin": "YubiKeyに指を押し当てて開始します", "p_will_change_label_fp": "これにより指紋のラベルが変更されます", + "@_fido_errors": {}, + "l_user_action_timeout_error": null, + "l_wrong_inserted_yk_error": null, + "l_failed_connecting_to_fido": null, + "@_certificates": {}, "s_certificate": "証明書", "s_csr": "CSR", diff --git a/lib/l10n/app_pl.arb b/lib/l10n/app_pl.arb index 44cd4c22..4e9a6fe4 100644 --- a/lib/l10n/app_pl.arb +++ b/lib/l10n/app_pl.arb @@ -406,6 +406,10 @@ "s_fingerprints": "Odciski palców", "l_fingerprint_captured": "Odcisk palca zarejestrowany pomyślnie!", "s_fingerprint_added": "Dodano odcisk palca", + "l_adding_fingerprint_failed": null, + "@l_adding_fingerprint_failed": { + "placeholders": {} + }, "l_setting_name_failed": "Błąd ustawienia nazwy: {message}", "@l_setting_name_failed": { "placeholders": { @@ -441,6 +445,11 @@ "p_press_fingerprint_begin": "Przytrzymaj palec na kluczu YubiKey, aby rozpocząć.", "p_will_change_label_fp": "Spowoduje to zmianę etykiety odcisku palca.", + "@_fido_errors": {}, + "l_user_action_timeout_error": null, + "l_wrong_inserted_yk_error": null, + "l_failed_connecting_to_fido": null, + "@_certificates": {}, "s_certificate": "Certyfikat", "s_csr": "CSR",