2023-04-27 10:13:38 +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-09 16:26:52 +03:00
|
|
|
import 'dart:async';
|
|
|
|
|
2023-04-27 10:13:38 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2024-03-08 11:30:47 +03:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2023-04-27 10:13:38 +03:00
|
|
|
|
|
|
|
import '../../app/message.dart';
|
|
|
|
import '../../app/models.dart';
|
|
|
|
import '../../app/shortcuts.dart';
|
2024-07-14 20:51:14 +03:00
|
|
|
import '../../app/state.dart';
|
2024-01-09 14:50:26 +03:00
|
|
|
import '../../app/views/action_list.dart';
|
2023-04-27 10:13:38 +03:00
|
|
|
import '../../app/views/app_failure_page.dart';
|
2023-06-15 18:39:17 +03:00
|
|
|
import '../../app/views/app_list_item.dart';
|
2023-04-27 10:13:38 +03:00
|
|
|
import '../../app/views/app_page.dart';
|
|
|
|
import '../../app/views/message_page.dart';
|
2023-09-29 15:12:11 +03:00
|
|
|
import '../../core/state.dart';
|
2024-01-23 14:28:21 +03:00
|
|
|
import '../../management/models.dart';
|
2023-06-15 18:39:17 +03:00
|
|
|
import '../../widgets/list_title.dart';
|
2023-11-27 13:41:05 +03:00
|
|
|
import '../features.dart' as features;
|
2023-11-28 13:30:22 +03:00
|
|
|
import '../keys.dart';
|
2023-04-27 10:13:38 +03:00
|
|
|
import '../models.dart';
|
|
|
|
import '../state.dart';
|
2023-06-15 18:39:17 +03:00
|
|
|
import 'actions.dart';
|
2024-01-09 14:50:26 +03:00
|
|
|
import 'cert_info_view.dart';
|
2023-04-27 10:13:38 +03:00
|
|
|
import 'key_actions.dart';
|
|
|
|
import 'slot_dialog.dart';
|
|
|
|
|
2024-01-10 22:47:54 +03:00
|
|
|
class PivScreen extends ConsumerStatefulWidget {
|
2023-04-27 10:13:38 +03:00
|
|
|
final DevicePath devicePath;
|
|
|
|
|
2024-01-10 22:47:54 +03:00
|
|
|
PivScreen(this.devicePath) : super(key: ObjectKey(devicePath));
|
2023-04-27 10:13:38 +03:00
|
|
|
|
|
|
|
@override
|
2024-01-10 22:47:54 +03:00
|
|
|
ConsumerState<ConsumerStatefulWidget> createState() => _PivScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PivScreenState extends ConsumerState<PivScreen> {
|
|
|
|
SlotId? _selected;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-04-27 10:13:38 +03:00
|
|
|
final l10n = AppLocalizations.of(context)!;
|
2023-09-29 15:12:11 +03:00
|
|
|
final hasFeature = ref.watch(featureProvider);
|
2024-07-14 20:51:14 +03:00
|
|
|
final (fipsCapable, fipsApproved) = ref
|
|
|
|
.watch(currentDeviceDataProvider)
|
|
|
|
.valueOrNull
|
|
|
|
?.info
|
|
|
|
.getFipsStatus(Capability.piv) ??
|
|
|
|
(false, false);
|
|
|
|
final fipsUnready = fipsCapable && !fipsApproved;
|
|
|
|
|
2024-01-10 22:47:54 +03:00
|
|
|
return ref.watch(pivStateProvider(widget.devicePath)).when(
|
2024-04-15 10:23:50 +03:00
|
|
|
loading: () => MessagePage(
|
|
|
|
title: l10n.s_certificates,
|
|
|
|
capabilities: const [Capability.piv],
|
2024-01-18 14:16:15 +03:00
|
|
|
centered: true,
|
2024-04-15 10:23:50 +03:00
|
|
|
graphic: const CircularProgressIndicator(),
|
2023-04-27 10:13:38 +03:00
|
|
|
delayedContent: true,
|
|
|
|
),
|
|
|
|
error: (error, _) => AppFailurePage(
|
|
|
|
cause: error,
|
|
|
|
),
|
|
|
|
data: (pivState) {
|
2024-01-10 22:47:54 +03:00
|
|
|
final pivSlots =
|
|
|
|
ref.watch(pivSlotsProvider(widget.devicePath)).asData;
|
|
|
|
final selected = _selected != null
|
|
|
|
? pivSlots?.value.firstWhere((e) => e.slot == _selected)
|
|
|
|
: null;
|
2024-03-20 17:42:17 +03:00
|
|
|
final normalSlots = pivSlots?.value
|
|
|
|
.where((element) => !element.slot.isRetired)
|
|
|
|
.toList() ??
|
|
|
|
[];
|
|
|
|
final shownRetiredSlots = pivSlots?.value
|
|
|
|
.where((element) =>
|
|
|
|
element.slot.isRetired &&
|
2024-04-10 15:45:32 +03:00
|
|
|
(element.certInfo != null || element.metadata != null))
|
2024-03-20 17:42:17 +03:00
|
|
|
.toList() ??
|
|
|
|
[];
|
2024-01-09 14:50:26 +03:00
|
|
|
final theme = Theme.of(context);
|
|
|
|
final textTheme = theme.textTheme;
|
|
|
|
// This is what ListTile uses for subtitle
|
|
|
|
final subtitleStyle = textTheme.bodyMedium!.copyWith(
|
2024-01-30 19:29:24 +03:00
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
2024-01-09 14:50:26 +03:00
|
|
|
);
|
2024-01-18 16:46:15 +03:00
|
|
|
return PivActions(
|
|
|
|
devicePath: widget.devicePath,
|
|
|
|
pivState: pivState,
|
2024-01-17 18:29:28 +03:00
|
|
|
builder: (context) => Actions(
|
|
|
|
actions: {
|
|
|
|
EscapeIntent:
|
|
|
|
CallbackAction<EscapeIntent>(onInvoke: (intent) {
|
|
|
|
if (selected != null) {
|
|
|
|
setState(() {
|
|
|
|
_selected = null;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Actions.invoke(context, intent);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}),
|
|
|
|
OpenIntent<PivSlot>: CallbackAction<OpenIntent<PivSlot>>(
|
|
|
|
onInvoke: (intent) async {
|
|
|
|
await showBlurDialog(
|
|
|
|
context: context,
|
|
|
|
barrierColor: Colors.transparent,
|
|
|
|
builder: (context) => SlotDialog(intent.target.slot),
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
child: AppPage(
|
2024-01-15 17:58:40 +03:00
|
|
|
title: l10n.s_certificates,
|
2024-01-26 13:59:37 +03:00
|
|
|
capabilities: const [Capability.piv],
|
2024-01-17 18:29:28 +03:00
|
|
|
detailViewBuilder: selected != null
|
|
|
|
? (context) => Column(
|
2024-01-10 19:52:27 +03:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
2024-01-09 14:50:26 +03:00
|
|
|
children: [
|
2024-01-10 19:52:27 +03:00
|
|
|
ListTitle(l10n.s_details),
|
2024-01-23 14:28:21 +03:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16.0),
|
|
|
|
child: Card(
|
|
|
|
elevation: 0.0,
|
|
|
|
color: Theme.of(context).hoverColor,
|
|
|
|
child: Padding(
|
2024-04-25 16:26:33 +03:00
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 16, vertical: 24),
|
2024-01-23 14:28:21 +03:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
selected.slot.getDisplayName(l10n),
|
|
|
|
style: textTheme.headlineSmall,
|
|
|
|
softWrap: true,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
2024-02-07 16:48:51 +03:00
|
|
|
if (selected.certInfo != null ||
|
|
|
|
selected.metadata != null) ...[
|
2024-03-26 15:27:03 +03:00
|
|
|
CertInfoTable(
|
|
|
|
selected.certInfo,
|
|
|
|
selected.metadata,
|
2024-04-15 13:31:55 +03:00
|
|
|
alwaysIncludePrivate:
|
|
|
|
pivState.supportsMetadata,
|
2024-08-23 18:14:44 +03:00
|
|
|
supportsBio: pivState.supportsBio,
|
2024-03-26 15:27:03 +03:00
|
|
|
),
|
2024-04-25 16:26:33 +03:00
|
|
|
if (selected.certInfo == null)
|
|
|
|
const SizedBox(height: 16)
|
2024-02-07 16:48:51 +03:00
|
|
|
],
|
|
|
|
if (selected.certInfo == null)
|
|
|
|
Text(
|
|
|
|
l10n.l_no_certificate,
|
|
|
|
softWrap: true,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: subtitleStyle,
|
|
|
|
),
|
2024-01-23 14:28:21 +03:00
|
|
|
],
|
|
|
|
),
|
2024-01-09 14:50:26 +03:00
|
|
|
),
|
|
|
|
),
|
2024-01-10 19:52:27 +03:00
|
|
|
),
|
2024-01-09 14:50:26 +03:00
|
|
|
ActionListSection.fromMenuActions(
|
|
|
|
context,
|
|
|
|
l10n.s_actions,
|
2024-07-14 20:51:14 +03:00
|
|
|
actions: buildSlotActions(
|
|
|
|
pivState, selected, fipsUnready, l10n),
|
2024-01-09 14:50:26 +03:00
|
|
|
),
|
|
|
|
],
|
2024-01-17 18:29:28 +03:00
|
|
|
)
|
|
|
|
: null,
|
|
|
|
keyActionsBuilder: hasFeature(features.actions)
|
|
|
|
? (context) => pivBuildActions(
|
|
|
|
context, widget.devicePath, pivState, ref)
|
|
|
|
: null,
|
2024-02-09 12:03:49 +03:00
|
|
|
keyActionsBadge: pivShowActionsNotifier(pivState),
|
2024-01-17 18:29:28 +03:00
|
|
|
builder: (context, expanded) {
|
|
|
|
// De-select if window is resized to be non-expanded.
|
2024-01-23 12:48:22 +03:00
|
|
|
if (!expanded && _selected != null) {
|
2024-01-17 18:29:28 +03:00
|
|
|
Timer.run(() {
|
|
|
|
setState(() {
|
|
|
|
_selected = null;
|
|
|
|
});
|
2024-01-10 22:47:54 +03:00
|
|
|
});
|
2024-01-17 18:29:28 +03:00
|
|
|
}
|
|
|
|
return Actions(
|
|
|
|
actions: {
|
|
|
|
if (expanded)
|
2024-01-18 16:46:15 +03:00
|
|
|
OpenIntent<PivSlot>:
|
|
|
|
CallbackAction<OpenIntent<PivSlot>>(
|
|
|
|
onInvoke: (intent) async {
|
2024-01-17 18:29:28 +03:00
|
|
|
setState(() {
|
|
|
|
_selected = intent.target.slot;
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
},
|
2024-08-08 14:06:34 +03:00
|
|
|
child: Padding(
|
2024-08-09 14:19:48 +03:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
2024-08-08 14:06:34 +03:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
...normalSlots.map(
|
|
|
|
(e) => _CertificateListItem(
|
|
|
|
pivState,
|
|
|
|
e,
|
|
|
|
expanded: expanded,
|
|
|
|
selected: e == selected,
|
2024-08-13 18:37:51 +03:00
|
|
|
fipsUnready: fipsUnready,
|
2024-08-08 14:06:34 +03:00
|
|
|
),
|
2024-03-20 17:42:17 +03:00
|
|
|
),
|
2024-08-08 14:06:34 +03:00
|
|
|
...shownRetiredSlots.map(
|
|
|
|
(e) => _CertificateListItem(
|
|
|
|
pivState,
|
|
|
|
e,
|
|
|
|
expanded: expanded,
|
|
|
|
selected: e == selected,
|
2024-08-13 18:37:51 +03:00
|
|
|
fipsUnready: fipsUnready,
|
2024-08-08 14:06:34 +03:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2024-01-17 18:29:28 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-04-27 10:13:38 +03:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-29 15:12:11 +03:00
|
|
|
class _CertificateListItem extends ConsumerWidget {
|
2024-03-18 13:32:03 +03:00
|
|
|
final PivState pivState;
|
2023-04-27 10:13:38 +03:00
|
|
|
final PivSlot pivSlot;
|
2024-01-09 16:26:52 +03:00
|
|
|
final bool expanded;
|
2024-01-10 22:47:54 +03:00
|
|
|
final bool selected;
|
2024-07-14 20:51:14 +03:00
|
|
|
final bool fipsUnready;
|
2023-11-28 13:30:22 +03:00
|
|
|
|
2024-03-18 13:32:03 +03:00
|
|
|
const _CertificateListItem(this.pivState, this.pivSlot,
|
2024-07-14 20:51:14 +03:00
|
|
|
{required this.expanded,
|
|
|
|
required this.selected,
|
|
|
|
required this.fipsUnready});
|
2023-04-27 10:13:38 +03:00
|
|
|
|
|
|
|
@override
|
2023-09-29 15:12:11 +03:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-04-27 10:13:38 +03:00
|
|
|
final slot = pivSlot.slot;
|
|
|
|
final certInfo = pivSlot.certInfo;
|
|
|
|
final l10n = AppLocalizations.of(context)!;
|
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
2023-09-29 15:12:11 +03:00
|
|
|
final hasFeature = ref.watch(featureProvider);
|
2023-06-15 18:39:17 +03:00
|
|
|
|
2024-01-09 16:26:52 +03:00
|
|
|
return AppListItem(
|
2024-01-17 18:29:28 +03:00
|
|
|
pivSlot,
|
2024-01-09 16:26:52 +03:00
|
|
|
selected: selected,
|
|
|
|
key: _getAppListItemKey(slot),
|
|
|
|
leading: CircleAvatar(
|
|
|
|
foregroundColor: colorScheme.onSecondary,
|
|
|
|
backgroundColor: colorScheme.secondary,
|
2024-03-27 13:31:50 +03:00
|
|
|
child: Text(pivSlot.slot.hexId),
|
2024-01-09 16:26:52 +03:00
|
|
|
),
|
2024-03-27 13:31:50 +03:00
|
|
|
title: slot.getSlotName(l10n),
|
2024-01-09 16:26:52 +03:00
|
|
|
subtitle: certInfo != null
|
|
|
|
// Simplify subtitle by stripping "CN=", etc.
|
|
|
|
? certInfo.subject.replaceAll(RegExp(r'[A-Z]+='), ' ').trimLeft()
|
2024-02-07 16:48:51 +03:00
|
|
|
: pivSlot.metadata != null
|
2024-01-09 16:26:52 +03:00
|
|
|
? l10n.l_key_no_certificate
|
|
|
|
: l10n.l_no_certificate,
|
|
|
|
trailing: expanded
|
|
|
|
? null
|
|
|
|
: OutlinedButton(
|
|
|
|
key: _getMeatballKey(slot),
|
2024-01-17 18:29:28 +03:00
|
|
|
onPressed: Actions.handler(context, OpenIntent(pivSlot)),
|
2024-03-08 11:30:47 +03:00
|
|
|
child: const Icon(Symbols.more_horiz),
|
2024-01-09 16:26:52 +03:00
|
|
|
),
|
2024-01-17 18:29:28 +03:00
|
|
|
tapIntent: isDesktop && !expanded ? null : OpenIntent(pivSlot),
|
|
|
|
doubleTapIntent: isDesktop && !expanded ? OpenIntent(pivSlot) : null,
|
2024-07-14 20:51:14 +03:00
|
|
|
buildPopupActions: hasFeature(features.slots) && !fipsUnready
|
|
|
|
? (context) => buildSlotActions(pivState, pivSlot, fipsUnready, l10n)
|
2024-01-09 16:26:52 +03:00
|
|
|
: null,
|
|
|
|
);
|
2023-04-27 10:13:38 +03:00
|
|
|
}
|
2023-11-28 13:30:22 +03:00
|
|
|
|
|
|
|
Key _getMeatballKey(SlotId slotId) => switch (slotId) {
|
|
|
|
SlotId.authentication => meatballButton9a,
|
|
|
|
SlotId.signature => meatballButton9c,
|
|
|
|
SlotId.keyManagement => meatballButton9d,
|
|
|
|
SlotId.cardAuth => meatballButton9e,
|
2024-03-20 16:35:17 +03:00
|
|
|
SlotId.retired1 => meatballButton82,
|
|
|
|
SlotId.retired2 => meatballButton83,
|
|
|
|
SlotId.retired3 => meatballButton84,
|
|
|
|
SlotId.retired4 => meatballButton85,
|
|
|
|
SlotId.retired5 => meatballButton86,
|
|
|
|
SlotId.retired6 => meatballButton87,
|
|
|
|
SlotId.retired7 => meatballButton88,
|
|
|
|
SlotId.retired8 => meatballButton89,
|
|
|
|
SlotId.retired9 => meatballButton8a,
|
|
|
|
SlotId.retired10 => meatballButton8b,
|
|
|
|
SlotId.retired11 => meatballButton8c,
|
|
|
|
SlotId.retired12 => meatballButton8d,
|
|
|
|
SlotId.retired13 => meatballButton8e,
|
|
|
|
SlotId.retired14 => meatballButton8f,
|
|
|
|
SlotId.retired15 => meatballButton90,
|
|
|
|
SlotId.retired16 => meatballButton91,
|
|
|
|
SlotId.retired17 => meatballButton92,
|
|
|
|
SlotId.retired18 => meatballButton93,
|
|
|
|
SlotId.retired19 => meatballButton94,
|
|
|
|
SlotId.retired20 => meatballButton95
|
2023-11-28 13:30:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
Key _getAppListItemKey(SlotId slotId) => switch (slotId) {
|
|
|
|
SlotId.authentication => appListItem9a,
|
|
|
|
SlotId.signature => appListItem9c,
|
|
|
|
SlotId.keyManagement => appListItem9d,
|
2024-03-20 16:35:17 +03:00
|
|
|
SlotId.cardAuth => appListItem9e,
|
|
|
|
SlotId.retired1 => appListItem82,
|
|
|
|
SlotId.retired2 => appListItem83,
|
|
|
|
SlotId.retired3 => appListItem84,
|
|
|
|
SlotId.retired4 => appListItem85,
|
|
|
|
SlotId.retired5 => appListItem86,
|
|
|
|
SlotId.retired6 => appListItem87,
|
|
|
|
SlotId.retired7 => appListItem88,
|
|
|
|
SlotId.retired8 => appListItem89,
|
|
|
|
SlotId.retired9 => appListItem8a,
|
|
|
|
SlotId.retired10 => appListItem8b,
|
|
|
|
SlotId.retired11 => appListItem8c,
|
|
|
|
SlotId.retired12 => appListItem8d,
|
|
|
|
SlotId.retired13 => appListItem8e,
|
|
|
|
SlotId.retired14 => appListItem8f,
|
|
|
|
SlotId.retired15 => appListItem90,
|
|
|
|
SlotId.retired16 => appListItem91,
|
|
|
|
SlotId.retired17 => appListItem92,
|
|
|
|
SlotId.retired18 => appListItem93,
|
|
|
|
SlotId.retired19 => appListItem94,
|
|
|
|
SlotId.retired20 => appListItem95
|
2023-11-28 13:30:22 +03:00
|
|
|
};
|
2023-04-27 10:13:38 +03:00
|
|
|
}
|