Пример #1
0
 def _raw_write(self, data):
     """
     Write data to YubiKey.
     """
     self._debug("YubiKey USB HID: WRITE : %s" % yubico_util.hexdump(data, colorize=True))
     request_type = _USB_TYPE_CLASS | _USB_RECIP_INTERFACE | _USB_ENDPOINT_OUT
     value = _REPORT_TYPE_FEATURE << 8  # apparently required for YubiKey 1.3.2, but not 2.2.x
     sent = self._usb_handle.controlMsg(request_type, _HID_SET_REPORT, data, value=value, timeout=_USB_TIMEOUT_MS)
     if sent != _FEATURE_RPT_SIZE:
         self.debug("Failed writing %i bytes (wrote %i) to USB HID YubiKey.\n" % (_FEATURE_RPT_SIZE, sent))
         raise YubiKeyUSBHIDError("Failed talking to USB HID YubiKey")
     return sent
Пример #2
0
 def _read(self):
     """ Read a USB HID feature report from the YubiKey. """
     request_type = _USB_TYPE_CLASS | _USB_RECIP_INTERFACE | _USB_ENDPOINT_IN
     value = _REPORT_TYPE_FEATURE << 8  # apparently required for YubiKey 1.3.2, but not 2.2.x
     recv = self._usb_handle.controlMsg(
         request_type, _HID_GET_REPORT, _FEATURE_RPT_SIZE, value=value, timeout=_USB_TIMEOUT_MS
     )
     if len(recv) != _FEATURE_RPT_SIZE:
         if self.debug:
             sys.stderr.write("Failed reading %i bytes (got %i) from USB HID YubiKey.\n" % (_FEATURE_RPT_SIZE, recv))
         raise YubiKeyUSBHIDError("Failed reading from USB HID YubiKey")
     data = "".join(chr(c) for c in recv)
     self._debug("YubiKey USB HID: READ  : %s" % yubico_util.hexdump(data, colorize=True))
     return data
Пример #3
0
 def _raw_write(self, data):
     """
     Write data to YubiKey.
     """
     self._debug("YubiKey USB HID: WRITE : %s" % yubico_util.hexdump(data, colorize=True))
     request_type = _USB_TYPE_CLASS | _USB_RECIP_INTERFACE | _USB_ENDPOINT_OUT
     value = _REPORT_TYPE_FEATURE << 8	# apparently required for YubiKey 1.3.2, but not 2.2.x
     sent = self._usb_handle.controlMsg(request_type,
                                       _HID_SET_REPORT,
                                       data,
                                       value = value,
                                       timeout = _USB_TIMEOUT_MS)
     if sent != _FEATURE_RPT_SIZE:
         self.debug("Failed writing %i bytes (wrote %i) to USB HID YubiKey.\n"
                    % (_FEATURE_RPT_SIZE, sent))
         raise YubiKeyUSBHIDError('Failed talking to USB HID YubiKey')
     return sent
Пример #4
0
 def _read(self):
     """ Read a USB HID feature report from the YubiKey. """
     request_type = _USB_TYPE_CLASS | _USB_RECIP_INTERFACE | _USB_ENDPOINT_IN
     value = _REPORT_TYPE_FEATURE << 8	# apparently required for YubiKey 1.3.2, but not 2.2.x
     recv = self._usb_handle.controlMsg(request_type,
                                       _HID_GET_REPORT,
                                       _FEATURE_RPT_SIZE,
                                       value = value,
                                       timeout = _USB_TIMEOUT_MS)
     if len(recv) != _FEATURE_RPT_SIZE:
         if self.debug:
             sys.stderr.write("Failed reading %i bytes (got %i) from USB HID YubiKey.\n"
                              % (_FEATURE_RPT_SIZE, recv))
         raise YubiKeyUSBHIDError('Failed reading from USB HID YubiKey')
     data = ''.join(chr(c) for c in recv)
     self._debug("YubiKey USB HID: READ  : %s" % yubico_util.hexdump(data, colorize=True))
     return data