2022-10-04 13:12:54 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 Yubico.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2024-01-23 12:48:22 +03:00
|
|
|
import 'dart:async';
|
|
|
|
|
2022-04-03 12:05:37 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-12 16:46:43 +03:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2022-04-03 12:05:37 +03:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
|
|
|
import '../../app/message.dart';
|
|
|
|
import '../../app/models.dart';
|
2023-05-03 22:20:48 +03:00
|
|
|
import '../../app/shortcuts.dart';
|
2024-01-10 13:26:37 +03:00
|
|
|
import '../../app/views/action_list.dart';
|
2024-01-22 18:14:14 +03:00
|
|
|
import '../../app/views/app_failure_page.dart';
|
2023-06-15 18:39:17 +03:00
|
|
|
import '../../app/views/app_list_item.dart';
|
2022-04-03 12:05:37 +03:00
|
|
|
import '../../app/views/app_page.dart';
|
2022-04-05 12:46:22 +03:00
|
|
|
import '../../app/views/message_page.dart';
|
2023-10-06 11:49:01 +03:00
|
|
|
import '../../core/state.dart';
|
2024-01-22 18:14:14 +03:00
|
|
|
import '../../management/models.dart';
|
2022-06-02 15:52:00 +03:00
|
|
|
import '../../widgets/list_title.dart';
|
2023-11-27 13:41:05 +03:00
|
|
|
import '../features.dart' as features;
|
2022-04-03 12:05:37 +03:00
|
|
|
import '../models.dart';
|
2022-04-04 12:15:38 +03:00
|
|
|
import '../state.dart';
|
2023-06-15 18:39:17 +03:00
|
|
|
import 'actions.dart';
|
2024-01-18 14:16:15 +03:00
|
|
|
import 'add_fingerprint_dialog.dart';
|
2023-05-03 22:20:48 +03:00
|
|
|
import 'fingerprint_dialog.dart';
|
2023-01-12 10:56:08 +03:00
|
|
|
import 'key_actions.dart';
|
2024-01-22 18:14:14 +03:00
|
|
|
import 'pin_dialog.dart';
|
|
|
|
import 'pin_entry_form.dart';
|
2022-04-03 12:05:37 +03:00
|
|
|
|
2024-01-22 18:14:14 +03:00
|
|
|
class FingerprintsScreen extends ConsumerWidget {
|
|
|
|
final YubiKeyData deviceData;
|
|
|
|
const FingerprintsScreen(this.deviceData, {super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final l10n = AppLocalizations.of(context)!;
|
|
|
|
return ref.watch(fidoStateProvider(deviceData.node.path)).when(
|
|
|
|
loading: () => AppPage(
|
|
|
|
centered: true,
|
|
|
|
delayedContent: true,
|
|
|
|
builder: (context, _) => const CircularProgressIndicator(),
|
|
|
|
),
|
|
|
|
error: (error, _) {
|
|
|
|
final enabled = deviceData
|
|
|
|
.info.config.enabledCapabilities[deviceData.node.transport] ??
|
|
|
|
0;
|
|
|
|
if (Capability.fido2.value & enabled == 0) {
|
|
|
|
return MessagePage(
|
|
|
|
title: l10n.s_fingerprints,
|
|
|
|
header: l10n.s_fido_disabled,
|
|
|
|
message: l10n.l_webauthn_req_fido2,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return AppFailurePage(
|
|
|
|
cause: error,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
data: (fidoState) {
|
|
|
|
return fidoState.unlocked
|
|
|
|
? _FidoUnlockedPage(deviceData.node, fidoState)
|
|
|
|
: _FidoLockedPage(deviceData.node, fidoState);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FidoLockedPage extends ConsumerWidget {
|
|
|
|
final DeviceNode node;
|
|
|
|
final FidoState state;
|
|
|
|
|
|
|
|
const _FidoLockedPage(this.node, this.state);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final l10n = AppLocalizations.of(context)!;
|
|
|
|
final hasFeature = ref.watch(featureProvider);
|
|
|
|
final hasActions = hasFeature(features.actions);
|
|
|
|
|
|
|
|
if (!state.hasPin) {
|
|
|
|
return MessagePage(
|
|
|
|
actions: [
|
|
|
|
ActionChip(
|
|
|
|
label: Text(l10n.s_set_pin),
|
|
|
|
onPressed: () async {
|
|
|
|
await showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => FidoPinDialog(node.path, state));
|
|
|
|
},
|
|
|
|
avatar: const Icon(Icons.pin_outlined),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
title: l10n.s_fingerprints,
|
|
|
|
header: '${l10n.s_fingerprints_get_started} (1/2)',
|
|
|
|
message: l10n.p_set_fingerprints_desc,
|
|
|
|
keyActionsBuilder: hasActions ? _buildActions : null,
|
|
|
|
keyActionsBadge: fidoShowActionsNotifier(state),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.forcePinChange) {
|
|
|
|
return MessagePage(
|
|
|
|
title: l10n.s_fingerprints,
|
|
|
|
header: l10n.s_pin_change_required,
|
|
|
|
message: l10n.l_pin_change_required_desc,
|
|
|
|
keyActionsBuilder: hasActions ? _buildActions : null,
|
|
|
|
keyActionsBadge: fidoShowActionsNotifier(state),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return AppPage(
|
|
|
|
title: l10n.s_fingerprints,
|
|
|
|
keyActionsBuilder: hasActions ? _buildActions : null,
|
|
|
|
builder: (context, _) => Column(
|
|
|
|
children: [
|
|
|
|
PinEntryForm(state, node),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildActions(BuildContext context) =>
|
|
|
|
fidoBuildActions(context, node, state, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FidoUnlockedPage extends ConsumerStatefulWidget {
|
2024-01-10 22:47:54 +03:00
|
|
|
final DeviceNode node;
|
|
|
|
final FidoState state;
|
2024-01-10 13:26:37 +03:00
|
|
|
|
2024-01-22 18:14:14 +03:00
|
|
|
_FidoUnlockedPage(this.node, this.state) : super(key: ObjectKey(node.path));
|
2024-01-10 13:26:37 +03:00
|
|
|
|
2024-01-10 22:47:54 +03:00
|
|
|
@override
|
|
|
|
ConsumerState<ConsumerStatefulWidget> createState() =>
|
|
|
|
_FidoUnlockedPageState();
|
2024-01-10 13:26:37 +03:00
|
|
|
}
|
|
|
|
|
2024-01-22 18:14:14 +03:00
|
|
|
class _FidoUnlockedPageState extends ConsumerState<_FidoUnlockedPage> {
|
|
|
|
Fingerprint? _selected;
|
2024-01-10 22:47:54 +03:00
|
|
|
|
2022-04-03 12:05:37 +03:00
|
|
|
@override
|
2024-01-10 22:47:54 +03:00
|
|
|
Widget build(BuildContext context) {
|
2023-02-28 21:05:46 +03:00
|
|
|
final l10n = AppLocalizations.of(context)!;
|
2024-01-10 13:26:37 +03:00
|
|
|
List<Widget Function(bool expanded)> children = [];
|
2023-10-06 11:49:01 +03:00
|
|
|
|
2022-08-12 14:08:31 +03:00
|
|
|
int nFingerprints = 0;
|
2024-01-10 22:47:54 +03:00
|
|
|
if (widget.state.bioEnroll != null) {
|
|
|
|
final data = ref.watch(fingerprintProvider(widget.node.path)).asData;
|
2022-05-24 17:41:57 +03:00
|
|
|
if (data == null) {
|
2022-09-12 17:14:58 +03:00
|
|
|
return _buildLoadingPage(context);
|
2022-05-24 17:41:57 +03:00
|
|
|
}
|
|
|
|
final fingerprints = data.value;
|
|
|
|
if (fingerprints.isNotEmpty) {
|
2022-08-12 14:08:31 +03:00
|
|
|
nFingerprints = fingerprints.length;
|
2024-01-17 18:29:28 +03:00
|
|
|
children.addAll(fingerprints.map(
|
|
|
|
(fp) => (expanded) => _FingerprintListItem(
|
|
|
|
fp,
|
|
|
|
expanded: expanded,
|
2024-01-18 16:46:15 +03:00
|
|
|
selected: fp == _selected,
|
2024-01-17 18:29:28 +03:00
|
|
|
),
|
|
|
|
));
|
2022-05-24 17:41:57 +03:00
|
|
|
}
|
|
|
|
}
|
2022-04-05 12:46:22 +03:00
|
|
|
|
2024-01-17 18:29:28 +03:00
|
|
|
final hasFeature = ref.watch(featureProvider);
|
|
|
|
final hasActions = hasFeature(features.actions);
|
2024-01-22 18:14:14 +03:00
|
|
|
final fingerprint = _selected;
|
2023-10-06 11:49:01 +03:00
|
|
|
|
2022-04-05 12:46:22 +03:00
|
|
|
if (children.isNotEmpty) {
|
2024-01-18 16:46:15 +03:00
|
|
|
return FidoActions(
|
|
|
|
devicePath: widget.node.path,
|
|
|
|
actions: (context) => {
|
2024-01-10 13:26:37 +03:00
|
|
|
EscapeIntent: CallbackAction<EscapeIntent>(onInvoke: (intent) {
|
2024-01-18 16:46:15 +03:00
|
|
|
if (_selected != null) {
|
2024-01-10 22:47:54 +03:00
|
|
|
setState(() {
|
|
|
|
_selected = null;
|
|
|
|
});
|
2024-01-10 13:26:37 +03:00
|
|
|
} else {
|
|
|
|
Actions.invoke(context, intent);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}),
|
2024-01-18 16:46:15 +03:00
|
|
|
OpenIntent<Fingerprint>:
|
|
|
|
CallbackAction<OpenIntent<Fingerprint>>(onInvoke: (intent) {
|
|
|
|
return showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
barrierColor: Colors.transparent,
|
|
|
|
builder: (context) => FingerprintDialog(intent.target),
|
|
|
|
);
|
|
|
|
}),
|
2024-01-17 18:29:28 +03:00
|
|
|
if (hasFeature(features.fingerprintsEdit))
|
|
|
|
EditIntent<Fingerprint>: CallbackAction<EditIntent<Fingerprint>>(
|
|
|
|
onInvoke: (intent) async {
|
2024-01-18 16:46:15 +03:00
|
|
|
final renamed =
|
|
|
|
await (Actions.invoke(context, intent) as Future<dynamic>?);
|
|
|
|
if (_selected == intent.target && renamed is Fingerprint) {
|
2024-01-17 18:29:28 +03:00
|
|
|
setState(() {
|
|
|
|
_selected = renamed;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return renamed;
|
|
|
|
}),
|
|
|
|
if (hasFeature(features.fingerprintsDelete))
|
|
|
|
DeleteIntent<Fingerprint>:
|
|
|
|
CallbackAction<DeleteIntent<Fingerprint>>(
|
|
|
|
onInvoke: (intent) async {
|
2024-01-18 16:46:15 +03:00
|
|
|
final deleted =
|
|
|
|
await (Actions.invoke(context, intent) as Future<dynamic>?);
|
|
|
|
if (deleted == true && _selected == intent.target) {
|
2024-01-17 18:29:28 +03:00
|
|
|
setState(() {
|
|
|
|
_selected = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return deleted;
|
|
|
|
}),
|
2024-01-10 13:26:37 +03:00
|
|
|
},
|
2024-01-18 16:46:15 +03:00
|
|
|
builder: (context) => AppPage(
|
2024-01-22 18:14:14 +03:00
|
|
|
title: l10n.s_fingerprints,
|
|
|
|
detailViewBuilder: fingerprint != null
|
|
|
|
? (context) => Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
ListTitle(l10n.s_details),
|
|
|
|
Card(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
// TODO: Reuse from fingerprint_dialog
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
fingerprint.label,
|
|
|
|
style:
|
|
|
|
Theme.of(context).textTheme.headlineSmall,
|
|
|
|
softWrap: true,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
const Icon(Icons.fingerprint, size: 72),
|
|
|
|
],
|
|
|
|
),
|
2024-01-10 13:26:37 +03:00
|
|
|
),
|
|
|
|
),
|
2024-01-22 18:14:14 +03:00
|
|
|
ActionListSection.fromMenuActions(
|
|
|
|
context,
|
|
|
|
l10n.s_actions,
|
|
|
|
actions: buildFingerprintActions(fingerprint, l10n),
|
2024-01-10 13:26:37 +03:00
|
|
|
),
|
2024-01-22 18:14:14 +03:00
|
|
|
],
|
|
|
|
)
|
|
|
|
: null,
|
2024-01-10 22:58:25 +03:00
|
|
|
keyActionsBuilder: hasActions
|
|
|
|
? (context) => fidoBuildActions(
|
|
|
|
context, widget.node, widget.state, nFingerprints)
|
|
|
|
: null,
|
2024-01-10 22:47:54 +03:00
|
|
|
keyActionsBadge: fidoShowActionsNotifier(widget.state),
|
2024-01-23 12:48:22 +03:00
|
|
|
builder: (context, expanded) {
|
|
|
|
// De-select if window is resized to be non-expanded.
|
|
|
|
if (!expanded && _selected != null) {
|
|
|
|
Timer.run(() {
|
|
|
|
setState(() {
|
|
|
|
_selected = null;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return Actions(
|
|
|
|
actions: {
|
|
|
|
if (expanded) ...{
|
|
|
|
OpenIntent<Fingerprint>:
|
|
|
|
CallbackAction<OpenIntent<Fingerprint>>(
|
|
|
|
onInvoke: (intent) {
|
|
|
|
setState(() {
|
|
|
|
_selected = intent.target;
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: children.map((f) => f(expanded)).toList()),
|
|
|
|
);
|
|
|
|
},
|
2024-01-10 13:26:37 +03:00
|
|
|
),
|
2022-04-05 12:46:22 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return MessagePage(
|
2024-01-22 18:14:14 +03:00
|
|
|
actions: [
|
|
|
|
ActionChip(
|
|
|
|
label: Text(l10n.s_add_fingerprint),
|
|
|
|
onPressed: () async {
|
|
|
|
await showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AddFingerprintDialog(widget.node.path));
|
|
|
|
},
|
|
|
|
avatar: const Icon(Icons.fingerprint_outlined),
|
|
|
|
)
|
|
|
|
],
|
2024-01-18 14:16:15 +03:00
|
|
|
title: l10n.s_webauthn,
|
2024-01-22 18:14:14 +03:00
|
|
|
header: '${l10n.s_fingerprints_get_started} (2/2)',
|
|
|
|
message: l10n.l_add_one_or_more_fps,
|
2023-10-06 11:49:01 +03:00
|
|
|
keyActionsBuilder: hasActions
|
2024-01-10 22:47:54 +03:00
|
|
|
? (context) => fidoBuildActions(context, widget.node, widget.state, 0)
|
2023-10-06 11:49:01 +03:00
|
|
|
: null,
|
2024-01-10 22:47:54 +03:00
|
|
|
keyActionsBadge: fidoShowActionsNotifier(widget.state),
|
2022-04-05 12:46:22 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-12 17:14:58 +03:00
|
|
|
Widget _buildLoadingPage(BuildContext context) => AppPage(
|
2022-05-24 17:41:57 +03:00
|
|
|
centered: true,
|
2022-12-20 18:07:16 +03:00
|
|
|
delayedContent: true,
|
2024-01-10 23:05:54 +03:00
|
|
|
builder: (context, _) => const CircularProgressIndicator(),
|
2022-05-24 17:41:57 +03:00
|
|
|
);
|
2022-04-03 12:05:37 +03:00
|
|
|
}
|
2023-05-03 22:20:48 +03:00
|
|
|
|
|
|
|
class _FingerprintListItem extends StatelessWidget {
|
|
|
|
final Fingerprint fingerprint;
|
2024-01-10 13:26:37 +03:00
|
|
|
final bool selected;
|
|
|
|
final bool expanded;
|
|
|
|
|
|
|
|
const _FingerprintListItem(this.fingerprint,
|
|
|
|
{required this.expanded, required this.selected});
|
2023-05-03 22:20:48 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-06-15 18:39:17 +03:00
|
|
|
return AppListItem(
|
2024-01-17 18:29:28 +03:00
|
|
|
fingerprint,
|
2024-01-10 13:26:37 +03:00
|
|
|
selected: selected,
|
2023-05-03 22:20:48 +03:00
|
|
|
leading: CircleAvatar(
|
|
|
|
foregroundColor: Theme.of(context).colorScheme.onSecondary,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.secondary,
|
|
|
|
child: const Icon(Icons.fingerprint),
|
|
|
|
),
|
2023-06-15 18:39:17 +03:00
|
|
|
title: fingerprint.label,
|
2024-01-10 13:26:37 +03:00
|
|
|
trailing: expanded
|
|
|
|
? null
|
|
|
|
: OutlinedButton(
|
2024-01-17 18:29:28 +03:00
|
|
|
onPressed: Actions.handler(context, OpenIntent(fingerprint)),
|
2024-01-10 13:26:37 +03:00
|
|
|
child: const Icon(Icons.more_horiz),
|
|
|
|
),
|
2024-01-17 18:29:28 +03:00
|
|
|
tapIntent: isDesktop && !expanded ? null : OpenIntent(fingerprint),
|
|
|
|
doubleTapIntent: isDesktop && !expanded ? OpenIntent(fingerprint) : null,
|
2023-06-15 18:39:17 +03:00
|
|
|
buildPopupActions: (context) =>
|
2024-01-17 18:29:28 +03:00
|
|
|
buildFingerprintActions(fingerprint, AppLocalizations.of(context)!),
|
2023-05-03 22:20:48 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|