2022-03-16 16:55:21 +03:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-03-15 19:16:14 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2022-03-23 19:50:49 +03:00
|
|
|
import 'package:yubico_authenticator/app/state.dart';
|
2022-03-15 19:16:14 +03:00
|
|
|
|
|
|
|
import '../../app/models.dart';
|
|
|
|
import '../../app/views/app_failure_screen.dart';
|
|
|
|
import '../../app/views/app_loading_screen.dart';
|
2022-03-18 18:10:05 +03:00
|
|
|
import '../../desktop/state.dart';
|
|
|
|
import '../../management/models.dart';
|
2022-03-22 16:23:12 +03:00
|
|
|
import '../models.dart';
|
2022-03-15 19:16:14 +03:00
|
|
|
import '../state.dart';
|
2022-03-23 19:50:49 +03:00
|
|
|
import 'credential_page.dart';
|
2022-03-22 16:23:12 +03:00
|
|
|
import 'fingerprint_page.dart';
|
|
|
|
import 'main_page.dart';
|
2022-03-15 19:16:14 +03:00
|
|
|
|
2022-03-23 19:50:49 +03:00
|
|
|
final _subPageProvider = StateProvider<SubPage>((ref) {
|
|
|
|
// Reset whenever the device changes.
|
|
|
|
ref.watch(currentDeviceProvider);
|
|
|
|
return SubPage.main;
|
|
|
|
});
|
|
|
|
|
2022-03-15 19:16:14 +03:00
|
|
|
class FidoScreen extends ConsumerWidget {
|
|
|
|
final YubiKeyData deviceData;
|
|
|
|
const FidoScreen(this.deviceData, {Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) =>
|
|
|
|
ref.watch(fidoStateProvider(deviceData.node.path)).when(
|
2022-03-24 00:55:18 +03:00
|
|
|
loading: () => const AppLoadingScreen(),
|
|
|
|
error: (error, _) {
|
2022-03-21 11:58:13 +03:00
|
|
|
final supported = deviceData
|
|
|
|
.info.supportedCapabilities[deviceData.node.transport]!;
|
|
|
|
if (Capability.fido2.value & supported == 0) {
|
2022-03-17 15:06:48 +03:00
|
|
|
return const AppFailureScreen(
|
|
|
|
'WebAuthn is supported by this device, but there are no management options available.');
|
|
|
|
}
|
2022-03-16 16:55:21 +03:00
|
|
|
if (Platform.isWindows) {
|
|
|
|
if (!ref
|
|
|
|
.watch(rpcStateProvider.select((state) => state.isAdmin))) {
|
|
|
|
return const AppFailureScreen(
|
|
|
|
'WebAuthn management requires elevated privileges.\nRestart this app as administrator.');
|
|
|
|
}
|
|
|
|
}
|
2022-03-24 00:55:18 +03:00
|
|
|
return AppFailureScreen('$error');
|
2022-03-16 16:55:21 +03:00
|
|
|
},
|
2022-03-24 00:55:18 +03:00
|
|
|
data: (state) {
|
2022-03-23 19:50:49 +03:00
|
|
|
setSubPage(value) {
|
|
|
|
ref.read(_subPageProvider.notifier).state = value;
|
|
|
|
}
|
2022-03-22 16:23:12 +03:00
|
|
|
|
2022-03-23 19:50:49 +03:00
|
|
|
switch (ref.watch(_subPageProvider)) {
|
|
|
|
case SubPage.fingerprints:
|
|
|
|
return WithBackButton(
|
|
|
|
goBack: () {
|
|
|
|
setSubPage(SubPage.main);
|
|
|
|
},
|
|
|
|
child: FingerprintPage(deviceData.node, state),
|
|
|
|
);
|
|
|
|
case SubPage.credentials:
|
|
|
|
return WithBackButton(
|
|
|
|
goBack: () {
|
|
|
|
setSubPage(SubPage.main);
|
|
|
|
},
|
|
|
|
child: CredentialPage(deviceData.node, state),
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return FidoMainPage(
|
|
|
|
deviceData.node,
|
|
|
|
state,
|
|
|
|
setSubPage: setSubPage,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2022-03-22 16:23:12 +03:00
|
|
|
}
|
|
|
|
|
2022-03-23 19:50:49 +03:00
|
|
|
class WithBackButton extends StatelessWidget {
|
|
|
|
final Function() goBack;
|
|
|
|
final Widget child;
|
|
|
|
const WithBackButton({Key? key, required this.goBack, required this.child})
|
|
|
|
: super(key: key);
|
2022-03-22 16:23:12 +03:00
|
|
|
|
|
|
|
@override
|
2022-03-23 19:50:49 +03:00
|
|
|
Widget build(BuildContext context) => Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
TextButton(onPressed: goBack, child: const Text('Back')),
|
|
|
|
Expanded(child: child),
|
|
|
|
],
|
|
|
|
);
|
2022-03-15 19:16:14 +03:00
|
|
|
}
|