From f33087fd0f681a0cf3028c83163bbca644a31a45 Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Fri, 20 May 2022 16:41:03 +0200 Subject: [PATCH] Customize error messages for connection failures. --- lib/app/views/app_failure_screen.dart | 32 +++++++++++++++++++-- lib/fido/views/fido_screen.dart | 10 ++++--- lib/management/views/management_screen.dart | 2 +- lib/oath/views/oath_screen.dart | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/app/views/app_failure_screen.dart b/lib/app/views/app_failure_screen.dart index 3f9bd484..a9bb756b 100755 --- a/lib/app/views/app_failure_screen.dart +++ b/lib/app/views/app_failure_screen.dart @@ -1,18 +1,46 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; +import 'package:yubico_authenticator/desktop/models.dart'; class AppFailureScreen extends StatelessWidget { - final String reason; + final Object reason; const AppFailureScreen(this.reason, {super.key}) : super(); @override Widget build(BuildContext context) { + final cause = reason; + if (cause is RpcError) { + if (cause.status == 'connection-error' && + cause.body['connection'] == 'ccid') { + var msg = 'Failed to open smart card connection'; + if (Platform.isMacOS) { + msg += '\nTry to remove and re-insert your YubiKey to regain access.'; + } else if (Platform.isLinux) { + msg += '\nMake sure pcscd is running.'; + } + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + msg, + textAlign: TextAlign.center, + ), + ], + ), + ); + } + } + return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( - reason, + cause.toString(), textAlign: TextAlign.center, ), ], diff --git a/lib/fido/views/fido_screen.dart b/lib/fido/views/fido_screen.dart index ad7cf554..8352144f 100755 --- a/lib/fido/views/fido_screen.dart +++ b/lib/fido/views/fido_screen.dart @@ -10,6 +10,7 @@ import '../../app/views/app_loading_screen.dart'; import '../../app/views/app_page.dart'; import '../../app/views/graphics.dart'; import '../../app/views/message_page.dart'; +import '../../desktop/models.dart'; import '../../desktop/state.dart'; import '../../management/models.dart'; import '../../theme.dart'; @@ -52,9 +53,10 @@ class FidoScreen extends ConsumerWidget { 'WebAuthn requires the FIDO2 application to be enabled on your YubiKey', ); } - if (Platform.isWindows) { - if (!ref - .watch(rpcStateProvider.select((state) => state.isAdmin))) { + if (Platform.isWindows && error is RpcError) { + if (error.status == 'connection-error' && + !ref.watch( + rpcStateProvider.select((state) => state.isAdmin))) { return MessagePage( title: const Text('WebAuthn'), graphic: noPermission, @@ -85,7 +87,7 @@ class FidoScreen extends ConsumerWidget { return AppPage( title: const Text('WebAuthn'), centered: true, - child: AppFailureScreen('$error'), + child: AppFailureScreen(error), ); }, data: (fidoState) { diff --git a/lib/management/views/management_screen.dart b/lib/management/views/management_screen.dart index 7c1af4d7..81ca1f10 100755 --- a/lib/management/views/management_screen.dart +++ b/lib/management/views/management_screen.dart @@ -241,7 +241,7 @@ class _ManagementScreenState extends ConsumerState { final child = ref.watch(managementStateProvider(widget.deviceData.node.path)).when( loading: () => const AppLoadingScreen(), - error: (error, _) => AppFailureScreen('$error'), + error: (error, _) => AppFailureScreen(error), data: (info) { bool hasConfig = info.version.major > 4; if (hasConfig) { diff --git a/lib/oath/views/oath_screen.dart b/lib/oath/views/oath_screen.dart index bcc39c4b..ab3005de 100755 --- a/lib/oath/views/oath_screen.dart +++ b/lib/oath/views/oath_screen.dart @@ -34,7 +34,7 @@ class OathScreen extends ConsumerWidget { error: (error, _) => AppPage( title: const Text('Authenticator'), centered: true, - child: AppFailureScreen('$error'), + child: AppFailureScreen(error), ), data: (oathState) => oathState.locked ? _LockedView(devicePath, oathState)