def set_mode(self, interfaces): with self._open_device() as dev: try: transports = sum([TRANSPORT[i] for i in interfaces]) dev.mode = Mode(transports & TRANSPORT.usb_transports()) except Exception as e: logger.error('Failed to set mode', exc_info=e) return str(e)
def refresh(self, otp_mode=False): descriptors = get_descriptors() if len(descriptors) != 1: self._descriptor = None return None desc = descriptors[0] unmatched_otp_mode = otp_mode and not desc.mode.has_transport( TRANSPORT.OTP) unmatched_ccid_mode = not otp_mode and not desc.mode.has_transport( TRANSPORT.CCID) if unmatched_otp_mode or unmatched_ccid_mode: return { 'transports': [t.name for t in TRANSPORT.split(desc.mode.transports)], 'usable': False, } if desc.fingerprint != ( self._descriptor.fingerprint if self._descriptor else None) \ or not otp_mode and not self._dev_info.get('version'): try: dev = desc.open_device( TRANSPORT.OTP if otp_mode else TRANSPORT.CCID) if otp_mode: version = None else: controller = OathController(dev.driver) version = controller.version except Exception as e: logger.debug('Failed to refresh YubiKey', exc_info=e) return None self._descriptor = desc self._dev_info = { 'usable': True, 'name': dev.device_name, 'version': version, 'serial': dev.serial or '', 'usb_interfaces_supported': [t.name for t in TRANSPORT if t & dev.config.usb_supported], 'usb_interfaces_enabled': str(dev.mode).split('+') } return self._dev_info
def refresh(self, otp_mode=False): descriptors = get_descriptors() if len(descriptors) != 1: self._descriptor = None return None desc = descriptors[0] unmatched_otp_mode = otp_mode and not desc.mode.has_transport( TRANSPORT.OTP) unmatched_ccid_mode = not otp_mode and not desc.mode.has_transport( TRANSPORT.CCID) if unmatched_otp_mode or unmatched_ccid_mode: return { 'transports': [ t.name for t in TRANSPORT.split(desc.mode.transports) ], 'usable': False, } if desc.fingerprint != ( self._descriptor.fingerprint if self._descriptor else None) \ or not otp_mode and not self._dev_info.get('version'): try: dev = desc.open_device(TRANSPORT.OTP if otp_mode else TRANSPORT.CCID) if otp_mode: version = None else: controller = OathController(dev.driver) version = controller.version except Exception as e: logger.debug('Failed to refresh YubiKey', exc_info=e) return None self._descriptor = desc self._dev_info = { 'usable': True, 'name': dev.device_name, 'version': version, 'serial': dev.serial or '', 'usb_interfaces_supported': [ t.name for t in TRANSPORT if t & dev.config.usb_supported], 'usb_interfaces_enabled': str(dev.mode).split('+') } return self._dev_info
def set_mode(self, interfaces): with self._open_device() as dev: transports = sum([TRANSPORT[i] for i in interfaces]) dev.mode = Mode(transports & TRANSPORT.usb_transports()) return success()