コード例 #1
0
ファイル: test_otp.py プロジェクト: maxthomas/yubikey-manager
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
ファイル: test_otp.py プロジェクト: maxthomas/yubikey-manager
 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
ファイル: yubikey.py プロジェクト: rsvargas/GAM
 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
ファイル: yubikey.py プロジェクト: rsvargas/GAM
 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]
     )