Remove broken caching, refresh OATH state on capability change

This commit is contained in:
Dain Nilsson 2024-09-12 10:11:25 +02:00
parent f38e5a5f46
commit ba7dac7923
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
3 changed files with 19 additions and 9 deletions

View File

@ -148,6 +148,7 @@ class RpcNode:
raise InvalidParametersException(e) raise InvalidParametersException(e)
def close(self): def close(self):
logger.debug(f"Closing node {self}")
self._closed = True self._closed = True
if self._child: if self._child:
self._close_child() self._close_child()

View File

@ -168,7 +168,7 @@ class ReadersNode(RpcNode):
return self._readers return self._readers
def create_child(self, name): def create_child(self, name):
return ReaderDeviceNode(self._reader_mapping[name], None) return ReaderDeviceNode(self._reader_mapping[name])
class _ScanDevices: class _ScanDevices:
@ -238,7 +238,7 @@ class DevicesNode(RpcNode):
dev_id = str(info.serial) dev_id = str(info.serial)
else: else:
dev_id = _id_from_fingerprint(dev.fingerprint) dev_id = _id_from_fingerprint(dev.fingerprint)
self._device_mapping[dev_id] = (dev, info) self._device_mapping[dev_id] = dev
name = get_name(info, dev.pid.yubikey_type if dev.pid else None) name = get_name(info, dev.pid.yubikey_type if dev.pid else None)
self._devices[dev_id] = dict(pid=dev.pid, name=name, serial=info.serial) self._devices[dev_id] = dict(pid=dev.pid, name=name, serial=info.serial)
@ -255,16 +255,16 @@ class DevicesNode(RpcNode):
if name not in self._device_mapping and self._list_state == 0: if name not in self._device_mapping and self._list_state == 0:
self.list_children() self.list_children()
try: try:
return UsbDeviceNode(*self._device_mapping[name]) return UsbDeviceNode(self._device_mapping[name])
except KeyError: except KeyError:
raise NoSuchNodeException(name) raise NoSuchNodeException(name)
class AbstractDeviceNode(RpcNode): class AbstractDeviceNode(RpcNode):
def __init__(self, device, info): def __init__(self, device):
super().__init__() super().__init__()
self._device = device self._device = device
self._info = info self._info = None
self._data = None self._data = None
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
@ -383,8 +383,8 @@ RESTRICTED_NDEF = bytes.fromhex("001fd1011b5504") + b"yubico.com/getting-started
class ReaderDeviceNode(AbstractDeviceNode): class ReaderDeviceNode(AbstractDeviceNode):
def __init__(self, device, info): def __init__(self, device):
super().__init__(device, info) super().__init__(device)
self._observer = _ReaderObserver(device) self._observer = _ReaderObserver(device)
self._monitor = CardMonitor() self._monitor = CardMonitor()
self._monitor.addObserver(self._observer) self._monitor.addObserver(self._observer)

View File

@ -28,6 +28,7 @@ import '../../app/logging.dart';
import '../../app/models.dart'; import '../../app/models.dart';
import '../../app/state.dart'; import '../../app/state.dart';
import '../../app/views/user_interaction.dart'; import '../../app/views/user_interaction.dart';
import '../../management/models.dart';
import '../../oath/models.dart'; import '../../oath/models.dart';
import '../../oath/state.dart'; import '../../oath/state.dart';
import '../rpc.dart'; import '../rpc.dart';
@ -37,8 +38,16 @@ final _log = Logger('desktop.oath.state');
final _sessionProvider = final _sessionProvider =
Provider.autoDispose.family<RpcNodeSession, DevicePath>( Provider.autoDispose.family<RpcNodeSession, DevicePath>(
(ref, devicePath) => RpcNodeSession( (ref, devicePath) {
ref.watch(rpcProvider).requireValue, devicePath, ['ccid', 'oath']), // Reset state if the OATH capability is toggled.
ref.watch(currentDeviceDataProvider.select((value) =>
(value.valueOrNull?.info.config
.enabledCapabilities[value.valueOrNull?.node.transport] ??
0) &
Capability.oath.value));
return RpcNodeSession(
ref.watch(rpcProvider).requireValue, devicePath, ['ccid', 'oath']);
},
); );
// This remembers the key for all devices for the duration of the process. // This remembers the key for all devices for the duration of the process.