Beispiel #1
0
    def refresh(self):
        devices, state = scan_devices()
        n_devs = sum(devices.values())
        if n_devs != 1:
            return failure('multiple_devices')

        if state != self._state:
            self._state = state
            try:
                connection, device, info = connect_to_device()
                connection.close()
            except:
                self._state = None
                self._dev_info = None
                return failure('no_device')

            interfaces = USB_INTERFACE(0)
            usb_supported = info.supported_capabilities.get(TRANSPORT.USB)
            if CAPABILITY.OTP & usb_supported:
                interfaces |= USB_INTERFACE.OTP
            if (CAPABILITY.U2F | CAPABILITY.FIDO2) & usb_supported:
                interfaces |= USB_INTERFACE.FIDO
            if (CAPABILITY.OPENPGP | CAPABILITY.PIV | CAPABILITY.OATH) & usb_supported:
                interfaces |= USB_INTERFACE.CCID

            self._dev_info = {
                'name': get_name(info, device.pid.get_type()).replace("YubiKey BIO", "YubiKey Bio"),
                'version': '.'.join(str(x) for x in info.version) if info.version else "",
                'serial': info.serial or '',
                'usb_enabled': [
                    a.name for a in CAPABILITY
                    if a in info.config.enabled_capabilities.get(TRANSPORT.USB)],
                'usb_supported': [
                    a.name for a in CAPABILITY
                    if a in info.supported_capabilities.get(TRANSPORT.USB)],
                'usb_interfaces_supported': [
                    t.name for t in USB_INTERFACE
                    if t in interfaces],
                'nfc_enabled': [
                    a.name for a in CAPABILITY
                    if a in info.config.enabled_capabilities.get(TRANSPORT.NFC, [])],
                'nfc_supported': [
                    a.name for a in CAPABILITY
                    if a in info.supported_capabilities.get(TRANSPORT.NFC, [])],
                'usb_interfaces_enabled': [i.name for i in USB_INTERFACE if i & device.pid.get_interfaces()],
                'can_write_config': info.version and info.version >= (5,0,0),
                'configuration_locked': info.is_locked,
                'form_factor': info.form_factor
            }

        return success({'dev': self._dev_info})
Beispiel #2
0
 def __init__(self, state):
     super().__init__(state)
     self._oath = OathSession(
         connect_to_device(state["yubikey"], [SmartCardConnection])[0])
Beispiel #3
0
 def _open_device(self, connection_types=[SmartCardConnection, FidoConnection, OtpConnection]):
     return connect_to_device(connection_types=connection_types)[0]