コード例 #1
0
def open_all_devices():
    max_index = c_uint()
    status = u2fh_devs_discover(devs, byref(max_index))
    if status == 0:
        # We have devices!
        devices = []
        resp = create_string_buffer(1024)
        for index in range(max_index.value + 1):
            buf_size = c_size_t(1024)
            if u2fh_get_device_description(
                    devs, index, resp, byref(buf_size)) == 0:
                if resp.value.startswith('Yubikey NEO'):
                    mode = MODE.mode_for_flags(
                        'OTP' in resp.value,
                        'CCID' in resp.value,
                        'U2F' in resp.value
                    )
                    devices.append(U2FDevice(devs, index, mode))
                elif resp.value.startswith('Yubikey 4'):
                    mode = MODE.mode_for_flags(
                        'OTP' in resp.value,
                        'CCID' in resp.value,
                        'U2F' in resp.value
                    )
                    devices.append(YK4Device(devs, index, mode))
                elif resp.value.startswith('Security Key by Yubico'):
                    devices.append(SKYDevice(devs, index))
        return devices
    else:
        # No devices!
        # u2fh_devs_done(devs)
        pass
    return []
コード例 #2
0
 def _read_mode(self, dev):
     vid = c_int()
     pid = c_int()
     try:
         yk_get_key_vid_pid(dev, byref(vid), byref(pid))
         mode = 0x0f & pid.value
         return MODE.mode_for_flags(bool(mode & 1), bool(mode & 4),
                                    bool(mode & 2))
     except:  # We know we at least have OTP enabled...
         return MODE.mode_for_flags(True, False, False)
コード例 #3
0
 def _read_mode(self, dev):
     vid = c_int()
     pid = c_int()
     try:
         yk_get_key_vid_pid(dev, byref(vid), byref(pid))
         mode = 0x0f & pid.value
         return MODE.mode_for_flags(bool(mode & 1), bool(mode & 4),
                                    bool(mode & 2))
     except:  # We know we at least have OTP enabled...
         return MODE.mode_for_flags(True, False, False)
コード例 #4
0
    def __init__(self, dev):
        self._dev = dev

        ser = c_uint()
        if yk_get_serial(dev, 0, 0, byref(ser)):
            self._serial = ser.value
        else:
            self._serial = None

        vid = c_int()
        pid = c_int()
        try:
            yk_get_key_vid_pid(dev, byref(vid), byref(pid))
            mode = 0x0f & pid.value
            if mode == 1:  # mode 1 has PID 0112 and mode 2 has PID 0111
                self._mode = 2
            elif mode == 2:
                self._mode = 1
            else:  # all others have 011x where x = mode
                self._mode = mode
        except:
            self._mode = MODE.mode_for_flags(True, False, False)

        status = ykds_alloc()
        try:
            if yk_get_status(dev, status):
                self._version = (ykds_version_major(status),
                                 ykds_version_minor(status),
                                 ykds_version_build(status))
            else:
                self._version = (0, 0, 0)
        finally:
            ykds_free(status)
コード例 #5
0
    def __init__(self, dev):
        self._dev = dev

        ser = c_uint()
        if yk_get_serial(dev, 0, 0, byref(ser)):
            self._serial = ser.value
        else:
            self._serial = None

        vid = c_int()
        pid = c_int()
        try:
            yk_get_key_vid_pid(dev, byref(vid), byref(pid))
            mode = 0x0f & pid.value
            if mode == 1:  # mode 1 has PID 0112 and mode 2 has PID 0111
                self._mode = 2
            elif mode == 2:
                self._mode = 1
            else:  # all others have 011x where x = mode
                self._mode = mode
        except:
            self._mode = MODE.mode_for_flags(True, False, False)

        status = ykds_alloc()
        try:
            if yk_get_status(dev, status):
                self._version = (
                    ykds_version_major(status),
                    ykds_version_minor(status),
                    ykds_version_build(status)
                )
            else:
                self._version = (0, 0, 0)
        finally:
            ykds_free(status)
コード例 #6
0
 def __init__(self,
              devs,
              index,
              mode=MODE.mode_for_flags(False, False, True)):
     self._devs = devs
     self._index = index
     self._mode = mode
     self._serial = None
     self._version = (0, 0, 0)
コード例 #7
0
class YKStandardDevice(BaseDevice):
    device_type = 'OTP'
    supported = False
    serial = None
    version = (0, 0, 0)
    mode = MODE.mode_for_flags(True, False, False)

    def __init__(self, version):
        self._version = version

    @property
    def default_name(self):
        return 'YubiKey %s' % '.'.join(map(str, self._version))
コード例 #8
0
 def _read_mode(self, dev):
     vid = c_int()
     pid = c_int()
     try:
         yk_get_key_vid_pid(dev, byref(vid), byref(pid))
         mode = 0x0f & pid.value
         if mode == 1:  # mode 1 has PID 0112 and mode 2 has PID 0111
             return 2
         elif mode == 2:
             return 1
         else:  # all others have 011x where x = mode
             return mode
     except:  # We know we at least have OTP enabled...
         return MODE.mode_for_flags(True, False, False)
コード例 #9
0
 def _read_mode(self, dev):
     vid = c_int()
     pid = c_int()
     try:
         yk_get_key_vid_pid(dev, byref(vid), byref(pid))
         mode = 0x0f & pid.value
         if mode == 1:  # mode 1 has PID 0112 and mode 2 has PID 0111
             return 2
         elif mode == 2:
             return 1
         else:  # all others have 011x where x = mode
             return mode
     except:  # We know we at least have OTP enabled...
         return MODE.mode_for_flags(True, False, False)
コード例 #10
0
class YKPlusDevice(YKStandardDevice):
    mode = MODE.mode_for_flags(True, False, True)
    default_name = 'YubiKey Plus'
コード例 #11
0
 def mode(self):
     return MODE.mode_for_flags(*self.flags)
コード例 #12
0
ファイル: neo.py プロジェクト: chosen1/yubikey-neo-manager
 def mode(self):
     return MODE.mode_for_flags(*self.flags)
コード例 #13
0
 def __init__(self, devs, index,
              mode=MODE.mode_for_flags(False, False, True)):
     self._devs = devs
     self._index = index
     self._mode = mode
     self._serial = None