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-30 17:45:47 +03:00
|
|
|
import '../../app/message.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-25 18:24:15 +03:00
|
|
|
import '../../app/views/app_page.dart';
|
2022-03-30 17:45:47 +03:00
|
|
|
import '../../app/views/device_avatar.dart';
|
2022-04-05 12:46:22 +03:00
|
|
|
import '../../app/views/message_page.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-04-03 12:05:37 +03:00
|
|
|
import 'locked_page.dart';
|
|
|
|
import 'unlocked_page.dart';
|
2022-03-23 19:50:49 +03:00
|
|
|
|
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
|
2022-04-03 12:05:37 +03:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) =>
|
|
|
|
ref.watch(fidoStateProvider(deviceData.node.path)).when(
|
|
|
|
loading: () => AppPage(
|
|
|
|
title: const Text('WebAuthn'),
|
|
|
|
centered: true,
|
|
|
|
child: const AppLoadingScreen(),
|
|
|
|
),
|
2022-03-24 00:55:18 +03:00
|
|
|
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-04-05 12:46:22 +03:00
|
|
|
return const MessagePage(
|
|
|
|
title: Text('WebAuthn'),
|
|
|
|
header: 'No management options',
|
|
|
|
message:
|
|
|
|
'WebAuthn is supported by this device, but there are no management options available.',
|
|
|
|
);
|
2022-03-17 15:06:48 +03:00
|
|
|
}
|
2022-03-16 16:55:21 +03:00
|
|
|
if (Platform.isWindows) {
|
|
|
|
if (!ref
|
|
|
|
.watch(rpcStateProvider.select((state) => state.isAdmin))) {
|
2022-04-03 12:05:37 +03:00
|
|
|
return AppPage(
|
|
|
|
title: const Text('WebAuthn'),
|
|
|
|
centered: true,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const DeviceAvatar(child: Icon(Icons.lock)),
|
|
|
|
const Text(
|
|
|
|
'WebAuthn management requires elevated privileges.',
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
OutlinedButton.icon(
|
|
|
|
icon: const Icon(Icons.lock_open),
|
|
|
|
label: const Text('Unlock'),
|
|
|
|
onPressed: () async {
|
|
|
|
final controller = showMessage(
|
|
|
|
context, 'Elevating permissions...',
|
|
|
|
duration: const Duration(seconds: 30));
|
|
|
|
try {
|
|
|
|
if (await ref.read(rpcProvider).elevate()) {
|
|
|
|
ref.refresh(rpcProvider);
|
|
|
|
} else {
|
|
|
|
showMessage(context, 'Permission denied');
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
controller.close();
|
2022-03-30 17:45:47 +03:00
|
|
|
}
|
2022-04-03 12:05:37 +03:00
|
|
|
}),
|
|
|
|
]
|
|
|
|
.map((e) => Padding(
|
|
|
|
child: e,
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 8.0),
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
));
|
2022-03-16 16:55:21 +03:00
|
|
|
}
|
|
|
|
}
|
2022-04-03 12:05:37 +03:00
|
|
|
return AppPage(
|
|
|
|
title: const Text('WebAuthn'),
|
|
|
|
centered: true,
|
|
|
|
child: AppFailureScreen('$error'),
|
|
|
|
);
|
2022-03-16 16:55:21 +03:00
|
|
|
},
|
2022-04-03 12:05:37 +03:00
|
|
|
data: (fidoState) {
|
|
|
|
return fidoState.unlocked
|
|
|
|
? FidoUnlockedPage(deviceData.node, fidoState)
|
|
|
|
: FidoLockedPage(deviceData.node, fidoState);
|
|
|
|
});
|
2022-03-15 19:16:14 +03:00
|
|
|
}
|