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.
|
|
|
|
*/
|
|
|
|
|
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';
|
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-05-18 15:11:17 +03:00
|
|
|
import '../../app/views/graphics.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';
|
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';
|
2023-05-04 17:20:50 +03:00
|
|
|
import 'credential_dialog.dart';
|
2023-06-15 18:39:17 +03:00
|
|
|
import 'delete_credential_dialog.dart';
|
|
|
|
import 'delete_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';
|
2023-06-15 18:39:17 +03:00
|
|
|
import 'rename_fingerprint_dialog.dart';
|
2022-04-03 12:05:37 +03:00
|
|
|
|
|
|
|
class FidoUnlockedPage extends ConsumerWidget {
|
|
|
|
final DeviceNode node;
|
|
|
|
final FidoState state;
|
|
|
|
|
2022-05-12 10:56:55 +03:00
|
|
|
const FidoUnlockedPage(this.node, this.state, {super.key});
|
2022-04-03 12:05:37 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-02-28 21:05:46 +03:00
|
|
|
final l10n = AppLocalizations.of(context)!;
|
2023-10-06 11:49:01 +03:00
|
|
|
final hasFeature = ref.watch(featureProvider);
|
2022-05-24 17:41:57 +03:00
|
|
|
List<Widget> children = [];
|
2023-10-06 11:49:01 +03:00
|
|
|
|
2022-05-24 17:41:57 +03:00
|
|
|
if (state.credMgmt) {
|
|
|
|
final data = ref.watch(credentialProvider(node.path)).asData;
|
|
|
|
if (data == null) {
|
2022-09-12 17:14:58 +03:00
|
|
|
return _buildLoadingPage(context);
|
2022-05-24 17:41:57 +03:00
|
|
|
}
|
|
|
|
final creds = data.value;
|
|
|
|
if (creds.isNotEmpty) {
|
2023-05-04 17:20:50 +03:00
|
|
|
children.add(ListTitle(l10n.s_passkeys));
|
|
|
|
children.addAll(creds.map((cred) => Actions(
|
|
|
|
actions: {
|
2023-06-15 18:39:17 +03:00
|
|
|
OpenIntent: CallbackAction<OpenIntent>(
|
|
|
|
onInvoke: (_) => showBlurDialog(
|
|
|
|
context: context,
|
2023-08-16 17:52:49 +03:00
|
|
|
barrierColor: Colors.transparent,
|
2023-06-15 18:39:17 +03:00
|
|
|
builder: (context) => CredentialDialog(cred),
|
|
|
|
)),
|
2023-10-06 11:49:01 +03:00
|
|
|
if (hasFeature(features.credentialsDelete))
|
|
|
|
DeleteIntent: CallbackAction<DeleteIntent>(
|
|
|
|
onInvoke: (_) => showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => DeleteCredentialDialog(
|
|
|
|
node.path,
|
|
|
|
cred,
|
|
|
|
),
|
2023-06-15 18:39:17 +03:00
|
|
|
),
|
|
|
|
),
|
2023-05-04 17:20:50 +03:00
|
|
|
},
|
|
|
|
child: _CredentialListItem(cred),
|
|
|
|
)));
|
2022-05-24 17:41:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-12 14:08:31 +03:00
|
|
|
int nFingerprints = 0;
|
2022-05-24 17:41:57 +03:00
|
|
|
if (state.bioEnroll != null) {
|
|
|
|
final data = ref.watch(fingerprintProvider(node.path)).asData;
|
|
|
|
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;
|
2023-03-02 14:45:55 +03:00
|
|
|
children.add(ListTitle(l10n.s_fingerprints));
|
2023-05-03 22:20:48 +03:00
|
|
|
children.addAll(fingerprints.map((fp) => Actions(
|
|
|
|
actions: {
|
2023-06-15 18:39:17 +03:00
|
|
|
OpenIntent: CallbackAction<OpenIntent>(
|
|
|
|
onInvoke: (_) => showBlurDialog(
|
|
|
|
context: context,
|
2023-08-16 17:52:49 +03:00
|
|
|
barrierColor: Colors.transparent,
|
2023-06-15 18:39:17 +03:00
|
|
|
builder: (context) => FingerprintDialog(fp),
|
|
|
|
)),
|
2023-10-06 11:49:01 +03:00
|
|
|
if (hasFeature(features.fingerprintsEdit))
|
|
|
|
EditIntent: CallbackAction<EditIntent>(
|
|
|
|
onInvoke: (_) => showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => RenameFingerprintDialog(
|
|
|
|
node.path,
|
|
|
|
fp,
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
if (hasFeature(features.fingerprintsDelete))
|
|
|
|
DeleteIntent: CallbackAction<DeleteIntent>(
|
|
|
|
onInvoke: (_) => showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => DeleteFingerprintDialog(
|
|
|
|
node.path,
|
|
|
|
fp,
|
|
|
|
),
|
|
|
|
)),
|
2023-05-03 22:20:48 +03:00
|
|
|
},
|
|
|
|
child: _FingerprintListItem(fp),
|
2022-05-24 17:41:57 +03:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|
2022-04-05 12:46:22 +03:00
|
|
|
|
2023-10-06 11:49:01 +03:00
|
|
|
final hasActions = ref.watch(featureProvider)(features.actions);
|
|
|
|
|
2022-04-05 12:46:22 +03:00
|
|
|
if (children.isNotEmpty) {
|
|
|
|
return AppPage(
|
2023-03-02 14:45:55 +03:00
|
|
|
title: Text(l10n.s_webauthn),
|
2023-10-06 11:49:01 +03:00
|
|
|
keyActionsBuilder: hasActions
|
|
|
|
? (context) => fidoBuildActions(context, node, state, nFingerprints)
|
|
|
|
: null,
|
2023-05-03 22:20:48 +03:00
|
|
|
keyActionsBadge: fidoShowActionsNotifier(state),
|
2022-06-02 15:52:00 +03:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, children: children),
|
2022-04-05 12:46:22 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-05-23 11:59:51 +03:00
|
|
|
if (state.bioEnroll != null) {
|
2022-04-05 12:46:22 +03:00
|
|
|
return MessagePage(
|
2023-03-02 14:45:55 +03:00
|
|
|
title: Text(l10n.s_webauthn),
|
2022-05-20 12:11:20 +03:00
|
|
|
graphic: noFingerprints,
|
2023-03-02 14:45:55 +03:00
|
|
|
header: l10n.s_no_fingerprints,
|
2023-02-28 21:05:46 +03:00
|
|
|
message: l10n.l_add_one_or_more_fps,
|
2023-10-06 11:49:01 +03:00
|
|
|
keyActionsBuilder: hasActions
|
|
|
|
? (context) => fidoBuildActions(context, node, state, 0)
|
|
|
|
: null,
|
2023-05-03 22:20:48 +03:00
|
|
|
keyActionsBadge: fidoShowActionsNotifier(state),
|
2022-04-05 12:46:22 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return MessagePage(
|
2023-03-02 14:45:55 +03:00
|
|
|
title: Text(l10n.s_webauthn),
|
2022-06-07 13:10:01 +03:00
|
|
|
graphic: manageAccounts,
|
2023-02-28 21:05:46 +03:00
|
|
|
header: l10n.l_no_discoverable_accounts,
|
|
|
|
message: l10n.l_register_sk_on_websites,
|
2023-10-06 11:49:01 +03:00
|
|
|
keyActionsBuilder: hasActions
|
|
|
|
? (context) => fidoBuildActions(context, node, state, 0)
|
|
|
|
: null,
|
2023-05-03 22:20:48 +03:00
|
|
|
keyActionsBadge: fidoShowActionsNotifier(state),
|
2022-04-05 12:46:22 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-12 17:14:58 +03:00
|
|
|
Widget _buildLoadingPage(BuildContext context) => AppPage(
|
2023-03-02 14:45:55 +03:00
|
|
|
title: Text(AppLocalizations.of(context)!.s_webauthn),
|
2022-05-24 17:41:57 +03:00
|
|
|
centered: true,
|
2022-12-20 18:07:16 +03:00
|
|
|
delayedContent: true,
|
2022-05-24 17:41:57 +03:00
|
|
|
child: const CircularProgressIndicator(),
|
|
|
|
);
|
2022-04-03 12:05:37 +03:00
|
|
|
}
|
2023-05-03 22:20:48 +03:00
|
|
|
|
2023-05-04 17:20:50 +03:00
|
|
|
class _CredentialListItem extends StatelessWidget {
|
|
|
|
final FidoCredential credential;
|
|
|
|
const _CredentialListItem(this.credential);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-06-15 18:39:17 +03:00
|
|
|
return AppListItem(
|
2023-05-04 17:20:50 +03:00
|
|
|
leading: CircleAvatar(
|
|
|
|
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
|
|
child: const Icon(Icons.person),
|
|
|
|
),
|
2023-06-15 18:39:17 +03:00
|
|
|
title: credential.userName,
|
|
|
|
subtitle: credential.rpId,
|
2023-05-04 17:20:50 +03:00
|
|
|
trailing: OutlinedButton(
|
2023-06-15 18:39:17 +03:00
|
|
|
onPressed: Actions.handler(context, const OpenIntent()),
|
2023-05-04 17:20:50 +03:00
|
|
|
child: const Icon(Icons.more_horiz),
|
|
|
|
),
|
2023-06-15 18:39:17 +03:00
|
|
|
buildPopupActions: (context) =>
|
|
|
|
buildCredentialActions(AppLocalizations.of(context)!),
|
2023-05-04 17:20:50 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-03 22:20:48 +03:00
|
|
|
class _FingerprintListItem extends StatelessWidget {
|
|
|
|
final Fingerprint fingerprint;
|
|
|
|
const _FingerprintListItem(this.fingerprint);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-06-15 18:39:17 +03:00
|
|
|
return AppListItem(
|
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,
|
2023-05-03 22:20:48 +03:00
|
|
|
trailing: OutlinedButton(
|
2023-06-15 18:39:17 +03:00
|
|
|
onPressed: Actions.handler(context, const OpenIntent()),
|
2023-05-03 22:20:48 +03:00
|
|
|
child: const Icon(Icons.more_horiz),
|
|
|
|
),
|
2023-06-15 18:39:17 +03:00
|
|
|
buildPopupActions: (context) =>
|
|
|
|
buildFingerprintActions(AppLocalizations.of(context)!),
|
2023-05-03 22:20:48 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|