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';
|
|
|
|
|
|
|
|
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-15 19:16:14 +03:00
|
|
|
import '../state.dart';
|
2022-03-18 18:10:05 +03:00
|
|
|
import 'pin_dialog.dart';
|
2022-03-17 22:10:10 +03:00
|
|
|
import 'reset_dialog.dart';
|
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(
|
|
|
|
none: () => const AppLoadingScreen(),
|
2022-03-16 16:55:21 +03:00
|
|
|
failure: (reason) {
|
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.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AppFailureScreen(reason);
|
|
|
|
},
|
2022-03-15 19:16:14 +03:00
|
|
|
success: (state) => ListView(
|
|
|
|
children: [
|
2022-03-17 15:06:48 +03:00
|
|
|
ListTile(
|
|
|
|
leading: const CircleAvatar(
|
|
|
|
child: Icon(Icons.pin),
|
|
|
|
),
|
|
|
|
title: const Text('PIN'),
|
|
|
|
subtitle:
|
|
|
|
Text(state.hasPin ? 'Change your PIN' : 'Set a PIN'),
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
FidoPinDialog(deviceData.node.path, state),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (state.bioEnroll != null)
|
|
|
|
ListTile(
|
|
|
|
leading: const CircleAvatar(
|
|
|
|
child: Icon(Icons.fingerprint),
|
|
|
|
),
|
|
|
|
title: const Text('Fingerprints'),
|
|
|
|
subtitle: Text(state.bioEnroll == true
|
|
|
|
? 'Fingerprints have been registered'
|
|
|
|
: 'No fingerprints registered'),
|
|
|
|
),
|
|
|
|
if (state.credMgmt)
|
|
|
|
const ListTile(
|
|
|
|
leading: CircleAvatar(
|
|
|
|
child: Icon(Icons.account_box),
|
|
|
|
),
|
|
|
|
title: Text('Credentials'),
|
|
|
|
subtitle: Text('Manage stored credentials on key'),
|
|
|
|
),
|
2022-03-17 22:10:10 +03:00
|
|
|
ListTile(
|
|
|
|
leading: const CircleAvatar(
|
2022-03-17 15:06:48 +03:00
|
|
|
child: Icon(Icons.delete_forever),
|
|
|
|
),
|
2022-03-17 22:10:10 +03:00
|
|
|
title: const Text('Factory reset'),
|
|
|
|
subtitle: const Text('Delete all data and remove PIN'),
|
|
|
|
onTap: () async {
|
|
|
|
await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => ResetDialog(deviceData.node),
|
|
|
|
);
|
|
|
|
},
|
2022-03-17 15:06:48 +03:00
|
|
|
),
|
2022-03-15 19:16:14 +03:00
|
|
|
],
|
|
|
|
));
|
|
|
|
}
|