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-05-12 12:06:28 +03:00
|
|
|
import 'package:collection/collection.dart';
|
2021-12-02 13:44:17 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2023-02-28 13:34:29 +03:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2023-11-27 13:41:05 +03:00
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
2022-05-12 12:06:28 +03:00
|
|
|
|
2021-11-19 17:05:57 +03:00
|
|
|
import '../../management/models.dart';
|
2022-03-16 14:43:56 +03:00
|
|
|
import '../core/models.dart';
|
2023-09-29 15:12:11 +03:00
|
|
|
import '../core/state.dart';
|
2021-11-19 17:05:57 +03:00
|
|
|
|
|
|
|
part 'models.freezed.dart';
|
|
|
|
|
2024-03-06 23:06:48 +03:00
|
|
|
part 'models.g.dart';
|
|
|
|
|
2022-03-16 14:43:56 +03:00
|
|
|
const _listEquality = ListEquality();
|
|
|
|
|
2022-03-14 12:57:00 +03:00
|
|
|
enum Availability { enabled, disabled, unsupported }
|
|
|
|
|
2022-05-12 11:14:11 +03:00
|
|
|
enum Application {
|
2024-03-06 23:06:48 +03:00
|
|
|
home(),
|
2024-01-26 13:59:37 +03:00
|
|
|
accounts([Capability.oath]),
|
|
|
|
webauthn([Capability.u2f]),
|
|
|
|
fingerprints([Capability.fido2]),
|
|
|
|
passkeys([Capability.fido2]),
|
|
|
|
certificates([Capability.piv]),
|
2024-02-03 18:12:51 +03:00
|
|
|
slots([Capability.otp]),
|
2024-01-26 13:59:37 +03:00
|
|
|
management();
|
2022-05-12 11:14:11 +03:00
|
|
|
|
2024-01-26 13:59:37 +03:00
|
|
|
final List<Capability> capabilities;
|
|
|
|
|
|
|
|
const Application([this.capabilities = const []]);
|
2022-03-14 12:57:00 +03:00
|
|
|
|
2023-05-22 12:52:49 +03:00
|
|
|
String getDisplayName(AppLocalizations l10n) => switch (this) {
|
2024-03-06 23:06:48 +03:00
|
|
|
Application.home => l10n.s_home,
|
2024-01-22 13:41:15 +03:00
|
|
|
Application.accounts => l10n.s_accounts,
|
|
|
|
Application.webauthn => l10n.s_webauthn,
|
|
|
|
Application.fingerprints => l10n.s_fingerprints,
|
2024-01-25 17:44:11 +03:00
|
|
|
Application.passkeys => l10n.s_passkeys,
|
2024-01-22 13:41:15 +03:00
|
|
|
Application.certificates => l10n.s_certificates,
|
|
|
|
Application.slots => l10n.s_slots,
|
2023-05-22 12:52:49 +03:00
|
|
|
_ => name.substring(0, 1).toUpperCase() + name.substring(1),
|
|
|
|
};
|
2023-02-28 13:34:29 +03:00
|
|
|
|
2022-03-14 12:57:00 +03:00
|
|
|
Availability getAvailability(YubiKeyData data) {
|
2022-03-14 13:48:39 +03:00
|
|
|
if (this == Application.management) {
|
2022-03-14 12:57:00 +03:00
|
|
|
final version = data.info.version;
|
|
|
|
final available = (version.major > 4 || // YK5 and up
|
|
|
|
(version.major == 4 && version.minor >= 1) || // YK4.1 and up
|
|
|
|
version.major == 3); // NEO
|
|
|
|
// Management can't be disabled
|
|
|
|
return available ? Availability.enabled : Availability.unsupported;
|
|
|
|
}
|
|
|
|
|
2024-02-03 18:12:51 +03:00
|
|
|
// TODO: Require credman for passkeys?
|
2024-01-22 13:41:15 +03:00
|
|
|
if (this == Application.fingerprints) {
|
|
|
|
if (!const {FormFactor.usbABio, FormFactor.usbCBio}
|
|
|
|
.contains(data.info.formFactor)) {
|
|
|
|
return Availability.unsupported;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 12:57:00 +03:00
|
|
|
final int supported =
|
|
|
|
data.info.supportedCapabilities[data.node.transport] ?? 0;
|
|
|
|
final int enabled =
|
|
|
|
data.info.config.enabledCapabilities[data.node.transport] ?? 0;
|
|
|
|
|
2024-02-03 18:12:51 +03:00
|
|
|
// Don't show WebAuthn if we have FIDO2
|
|
|
|
if (this == Application.webauthn &&
|
|
|
|
Capability.fido2.value & supported != 0) {
|
|
|
|
return Availability.unsupported;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for all bits in capabilities:
|
|
|
|
final bitmask = capabilities.map((c) => c.value).sum;
|
|
|
|
if (supported & bitmask == bitmask) {
|
|
|
|
if (enabled & bitmask == bitmask) {
|
|
|
|
return Availability.enabled;
|
|
|
|
}
|
|
|
|
return Availability.disabled;
|
|
|
|
}
|
|
|
|
return Availability.unsupported;
|
2022-03-14 12:57:00 +03:00
|
|
|
}
|
2022-03-04 19:45:08 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 14:49:04 +03:00
|
|
|
@freezed
|
|
|
|
class YubiKeyData with _$YubiKeyData {
|
|
|
|
factory YubiKeyData(DeviceNode node, String name, DeviceInfo info) =
|
|
|
|
_YubiKeyData;
|
|
|
|
}
|
|
|
|
|
2022-02-08 15:44:35 +03:00
|
|
|
class DevicePath {
|
|
|
|
final List<String> segments;
|
|
|
|
|
|
|
|
DevicePath(List<String> path) : segments = List.unmodifiable(path);
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) =>
|
|
|
|
other is DevicePath && _listEquality.equals(segments, other.segments);
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode => Object.hashAll(segments);
|
2022-03-18 13:22:24 +03:00
|
|
|
|
|
|
|
String get key => segments.join('/');
|
2022-04-03 12:03:03 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() => key;
|
2022-02-08 15:44:35 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 14:49:04 +03:00
|
|
|
@freezed
|
|
|
|
class DeviceNode with _$DeviceNode {
|
2022-03-07 11:57:29 +03:00
|
|
|
const DeviceNode._();
|
2022-01-12 14:49:04 +03:00
|
|
|
factory DeviceNode.usbYubiKey(
|
2022-03-16 14:43:56 +03:00
|
|
|
DevicePath path, String name, UsbPid pid, DeviceInfo? info) =
|
|
|
|
UsbYubiKeyNode;
|
2022-02-08 15:44:35 +03:00
|
|
|
factory DeviceNode.nfcReader(DevicePath path, String name) = NfcReaderNode;
|
2022-03-07 11:57:29 +03:00
|
|
|
|
|
|
|
Transport get transport =>
|
|
|
|
map(usbYubiKey: (_) => Transport.usb, nfcReader: (_) => Transport.nfc);
|
2022-01-12 14:49:04 +03:00
|
|
|
}
|
|
|
|
|
2023-06-15 18:39:17 +03:00
|
|
|
enum ActionStyle { normal, primary, error }
|
|
|
|
|
2021-12-02 13:44:17 +03:00
|
|
|
@freezed
|
2023-06-15 18:39:17 +03:00
|
|
|
class ActionItem with _$ActionItem {
|
|
|
|
factory ActionItem({
|
2022-09-28 18:31:17 +03:00
|
|
|
required Widget icon,
|
2023-06-15 18:39:17 +03:00
|
|
|
required String title,
|
|
|
|
String? subtitle,
|
|
|
|
String? shortcut,
|
|
|
|
Widget? trailing,
|
2023-02-10 19:37:42 +03:00
|
|
|
Intent? intent,
|
2023-06-15 18:39:17 +03:00
|
|
|
ActionStyle? actionStyle,
|
|
|
|
Key? key,
|
2023-09-29 15:12:11 +03:00
|
|
|
Feature? feature,
|
2023-06-15 18:39:17 +03:00
|
|
|
}) = _ActionItem;
|
2021-12-02 13:44:17 +03:00
|
|
|
}
|
2021-12-03 12:27:29 +03:00
|
|
|
|
|
|
|
@freezed
|
|
|
|
class WindowState with _$WindowState {
|
|
|
|
factory WindowState({
|
|
|
|
required bool focused,
|
|
|
|
required bool visible,
|
|
|
|
required bool active,
|
2023-02-24 16:10:39 +03:00
|
|
|
@Default(false) bool hidden,
|
2021-12-03 12:27:29 +03:00
|
|
|
}) = _WindowState;
|
|
|
|
}
|
2024-03-06 23:06:48 +03:00
|
|
|
|
|
|
|
@freezed
|
|
|
|
class KeyCustomization with _$KeyCustomization {
|
|
|
|
factory KeyCustomization({
|
|
|
|
required int serial,
|
|
|
|
@JsonKey(includeIfNull: false) String? name,
|
|
|
|
@JsonKey(includeIfNull: false) @_ColorConverter() Color? color,
|
|
|
|
}) = _KeyCustomization;
|
|
|
|
|
|
|
|
factory KeyCustomization.fromJson(Map<String, dynamic> json) =>
|
|
|
|
_$KeyCustomizationFromJson(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ColorConverter implements JsonConverter<Color?, int?> {
|
|
|
|
const _ColorConverter();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Color? fromJson(int? json) => json != null ? Color(json) : null;
|
|
|
|
|
|
|
|
@override
|
|
|
|
int? toJson(Color? object) => object?.value;
|
|
|
|
}
|