2021-12-02 13:44:17 +03:00
|
|
|
import 'package:flutter/material.dart';
|
2021-11-19 17:05:57 +03:00
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
import '../../management/models.dart';
|
|
|
|
|
|
|
|
part 'models.freezed.dart';
|
|
|
|
|
2022-03-14 12:57:00 +03:00
|
|
|
enum Availability { enabled, disabled, unsupported }
|
|
|
|
|
2022-03-14 13:48:39 +03:00
|
|
|
enum Application { oath, fido, otp, piv, openpgp, hsmauth, management }
|
2021-11-19 17:05:57 +03:00
|
|
|
|
2022-03-14 13:48:39 +03:00
|
|
|
extension Applications on Application {
|
2022-03-14 12:57:00 +03:00
|
|
|
String get displayName {
|
|
|
|
switch (this) {
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.oath:
|
2022-03-14 12:57:00 +03:00
|
|
|
return 'Authenticator';
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.fido:
|
2022-03-14 12:57:00 +03:00
|
|
|
return 'WebAuthn';
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.otp:
|
2022-03-14 12:57:00 +03:00
|
|
|
return 'One-Time Passwords';
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.piv:
|
2022-03-14 12:57:00 +03:00
|
|
|
return 'Certificates';
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.openpgp:
|
|
|
|
return 'OpenPGP';
|
|
|
|
case Application.hsmauth:
|
|
|
|
return 'YubiHSM Auth';
|
|
|
|
case Application.management:
|
2022-03-14 12:57:00 +03:00
|
|
|
return 'Toggle applications';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool _inCapabilities(int capabilities) {
|
2022-03-04 19:45:08 +03:00
|
|
|
switch (this) {
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.oath:
|
2022-03-04 19:45:08 +03:00
|
|
|
return Capability.oath.value & capabilities != 0;
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.fido:
|
2022-03-04 19:45:08 +03:00
|
|
|
return (Capability.u2f.value | Capability.fido2.value) & capabilities !=
|
|
|
|
0;
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.otp:
|
2022-03-04 19:45:08 +03:00
|
|
|
return Capability.otp.value & capabilities != 0;
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.piv:
|
2022-03-04 19:45:08 +03:00
|
|
|
return Capability.piv.value & capabilities != 0;
|
2022-03-14 13:48:39 +03:00
|
|
|
case Application.openpgp:
|
|
|
|
return Capability.openpgp.value & capabilities != 0;
|
|
|
|
case Application.hsmauth:
|
|
|
|
return Capability.hsmauth.value & capabilities != 0;
|
|
|
|
case Application.management:
|
2022-03-04 19:45:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
final int supported =
|
|
|
|
data.info.supportedCapabilities[data.node.transport] ?? 0;
|
|
|
|
final int enabled =
|
|
|
|
data.info.config.enabledCapabilities[data.node.transport] ?? 0;
|
|
|
|
|
|
|
|
return _inCapabilities(supported)
|
|
|
|
? (_inCapabilities(enabled)
|
|
|
|
? Availability.enabled
|
|
|
|
: Availability.disabled)
|
|
|
|
: Availability.unsupported;
|
|
|
|
}
|
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
|
|
|
const _listEquality = ListEquality();
|
|
|
|
|
|
|
|
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-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-07 17:36:49 +03:00
|
|
|
DevicePath path, String name, int 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
|
|
|
}
|
|
|
|
|
2021-12-02 13:44:17 +03:00
|
|
|
@freezed
|
|
|
|
class MenuAction with _$MenuAction {
|
|
|
|
factory MenuAction(
|
|
|
|
{required String text,
|
2022-03-03 15:55:07 +03:00
|
|
|
required Widget icon,
|
2022-02-08 17:40:26 +03:00
|
|
|
void Function(BuildContext context)? action}) = _MenuAction;
|
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,
|
|
|
|
}) = _WindowState;
|
|
|
|
}
|