Пример #1
0
def session(conn_type, info, device):
    if device.transport == TRANSPORT.NFC:
        with device.open_connection(conn_type) as c:
            yield YubiOtpSession(c)
    else:
        with connect_to_device(info.serial, [conn_type])[0] as c:
            yield YubiOtpSession(c)
Пример #2
0
def ccid_connection(device, info):
    if device.transport == TRANSPORT.NFC:
        with device.open_connection(SmartCardConnection) as c:
            yield c
    elif USB_INTERFACE.CCID in device.pid.get_interfaces():
        with connect_to_device(info.serial, [SmartCardConnection])[0] as c:
            yield c
    else:
        pytest.skip("CCID connection not available")
Пример #3
0
 def try_connection(self, interface):
     for _ in range(8):
         try:
             conn = connect_to_device(None,
                                      get_connection_types(interface))[0]
             conn.close()
             return
         except Exception:
             sleep(0.5)
     self.fail("Failed connecting to device over " + interface.name)
Пример #4
0
        def _open_oath(self):
            if self._reader_filter:
                dev = self._get_dev_from_reader()
                if dev:
                    return OathContextManager(dev.open_connection(SmartCardConnection))
                else:
                    raise ValueError("no_device_custom_reader")

            return OathContextManager(
                connect_to_device(self._current_serial, [SmartCardConnection])[0]
            )
Пример #5
0
 def call():
     otp = session
     if need_reboot:
         protocol = session.backend.protocol
         if transport == TRANSPORT.NFC:
             protocol.connection.connection.disconnect()
             conn = protocol.connection
             conn.connection.connect()
         else:
             ManagementSession(protocol.connection).write_device_config(reboot=True)
             await_reboot()
             conn = connect_to_device(info.serial, [SmartCardConnection])[0]
         otp = YubiOtpSession(conn)
         session.backend = otp.backend
     return otp.get_config_state()
Пример #6
0
 def _get_devices(self, otp_mode=False):
     res = []
     for dev, info in list_all_devices():
         usb_enabled = info.config.enabled_capabilities[TRANSPORT.USB]
         interfaces_enabled = []
         if CAPABILITY.OTP & usb_enabled:
             interfaces_enabled.append("OTP")
         if (CAPABILITY.U2F | CAPABILITY.FIDO2) & usb_enabled:
             interfaces_enabled.append("FIDO")
         if (
             CAPABILITY.OATH | CAPABILITY.PIV | CAPABILITY.OPENPGP
         ) & usb_enabled:
             interfaces_enabled.append("CCID")
         if otp_mode:
             selectable = "OTP" in interfaces_enabled
             has_password = False
         else:
             selectable = "CCID" in interfaces_enabled
             if selectable:
                 with connect_to_device(info.serial, [SmartCardConnection])[
                     0
                 ] as conn:
                     oath = OathSession(conn)
                     has_password = oath.locked
             else:
                 has_password = False
         res.append(
             {
                 "name": get_name(info, dev.pid.get_type()),
                 "version": ".".join(str(d) for d in info.version),
                 "serial": info.serial or "",
                 "usbInterfacesEnabled": interfaces_enabled,
                 "hasPassword": has_password,
                 "selectable": selectable,
                 "validated": not has_password,
             }
         )
     return res
Пример #7
0
def try_connection(conn_type):
    with connect_to_device(None, [conn_type])[0]:
        return True
Пример #8
0
 def get_serial_number(self):
     try:
         _, _, info = connect_to_device(self.serial_number)
         return info.serial
     except ValueError as err:
         controlflow.system_error_exit(9, f'YubiKey - {err}')
Пример #9
0
 def _connect(self):
     try:
         conn, _, _ = connect_to_device(self.serial_number)
     except CardConnectionException as err:
         controlflow.system_error_exit(9, f'YubiKey - {err}')
     return conn
Пример #10
0
def fido_connection(device, info):
    if USB_INTERFACE.FIDO in device.pid.get_interfaces():
        with connect_to_device(info.serial, [FidoConnection])[0] as c:
            yield c
Пример #11
0
def otp_connection(device, info):
    if USB_INTERFACE.OTP in device.pid.get_interfaces():
        with connect_to_device(info.serial, [OtpConnection])[0] as c:
            yield c
Пример #12
0
 def _open_otp(self):
     return OtpContextManager(
         connect_to_device(self._current_serial, [OtpConnection])[0]
     )