Skip to content

Commit

Permalink
Remove broken caching, refresh OATH state on capability change
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Sep 12, 2024
1 parent f38e5a5 commit ba7dac7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions helper/helper/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def __call__(self, action, target, params, event, signal, traversed=None):
raise InvalidParametersException(e)

def close(self):
logger.debug(f"Closing node {self}")
self._closed = True
if self._child:
self._close_child()
Expand Down
14 changes: 7 additions & 7 deletions helper/helper/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def list_children(self):
return self._readers

def create_child(self, name):
return ReaderDeviceNode(self._reader_mapping[name], None)
return ReaderDeviceNode(self._reader_mapping[name])


class _ScanDevices:
Expand Down Expand Up @@ -238,7 +238,7 @@ def list_children(self):
dev_id = str(info.serial)
else:
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)
self._devices[dev_id] = dict(pid=dev.pid, name=name, serial=info.serial)

Expand All @@ -255,16 +255,16 @@ def create_child(self, name):
if name not in self._device_mapping and self._list_state == 0:
self.list_children()
try:
return UsbDeviceNode(*self._device_mapping[name])
return UsbDeviceNode(self._device_mapping[name])
except KeyError:
raise NoSuchNodeException(name)


class AbstractDeviceNode(RpcNode):
def __init__(self, device, info):
def __init__(self, device):
super().__init__()
self._device = device
self._info = info
self._info = None
self._data = None

def __call__(self, *args, **kwargs):
Expand Down Expand Up @@ -383,8 +383,8 @@ def update(self, observable, actions):


class ReaderDeviceNode(AbstractDeviceNode):
def __init__(self, device, info):
super().__init__(device, info)
def __init__(self, device):
super().__init__(device)
self._observer = _ReaderObserver(device)
self._monitor = CardMonitor()
self._monitor.addObserver(self._observer)
Expand Down
13 changes: 11 additions & 2 deletions lib/desktop/oath/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import '../../app/logging.dart';
import '../../app/models.dart';
import '../../app/state.dart';
import '../../app/views/user_interaction.dart';
import '../../management/models.dart';
import '../../oath/models.dart';
import '../../oath/state.dart';
import '../rpc.dart';
Expand All @@ -37,8 +38,16 @@ final _log = Logger('desktop.oath.state');

final _sessionProvider =
Provider.autoDispose.family<RpcNodeSession, DevicePath>(
(ref, devicePath) => RpcNodeSession(
ref.watch(rpcProvider).requireValue, devicePath, ['ccid', 'oath']),
(ref, devicePath) {
// 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.
Expand Down

0 comments on commit ba7dac7

Please sign in to comment.