Codebase list python-yubico / upstream/1.2.3
Imported Upstream version 1.2.3 Dain Nilsson 9 years ago
7 changed file(s) with 128 addition(s) and 57 deletion(s). Raw diff Collapse all Expand all
0 2015-03-23 Dain Nilsson <dain@yubico.com>
1
2 * NEWS, yubico/__init__.py: Updated version.
3
4 2015-03-23 Dain Nilsson <dain@yubico.com>
5
6 * yubico/yubikey_usb_hid.py: Added PIDs and ignore failure to
7 setConfiguration.
8
9 2015-02-24 Henrik Stråth <minisu@users.noreply.github.com>
10
11 * README: Update README
12
13 2015-02-24 Henrik Stråth <minisu@users.noreply.github.com>
14
15 * README: Updated link to PyUSB. Closes #16
16
17 2015-02-24 Henrik Stråth <minisu@users.noreply.github.com>
18
19 * : Merge pull request #15 from vladimir-v-diaz/patch-2 Update README
20
21 2015-02-23 Vladimir Diaz <vladimir.v.diaz@gmail.com>
22
23 * README: Update README Provide pip installation instructions for `pyusb`
24
25 2015-02-19 Vladimir Diaz <vladimir.v.diaz@gmail.com>
26
27 * README: Update README Specify the correct package in the `pip install` installation
28 instruction.
29
030 2015-02-11 Dain Nilsson <dain@yubico.com>
131
232 * NEWS: Updated NEWS for release.
0 * Version 1.2.3 (released 2015-03-23)
1 ** Added PIDs for newer devices.
2 ** Failure to call setConfiguration is now ignored.
3
04 * Version 1.2.2 (released 2015-02-11)
15 ** Fixed bug in yubikey-totp using wrong timestamp.
26 ** No longer require nose for setup, only for tests.
00 Metadata-Version: 1.1
11 Name: python-yubico
2 Version: 1.2.2
2 Version: 1.2.3
33 Summary: Python code for talking to Yubico's YubiKeys
44 Home-page: https://github.com/Yubico/python-yubico
55 Author: Yubico Open Source Maintainers
00 == python-yubico
11 Python package for talking to YubiKeys.
2
3 Copyright (c) Yubico AB
4 Licensed under the BSD 2-clause license.
5 See the file COPYING for full licence statement.
62
73 === Introduction
84 The YubiKey is a hardware token for authentication. The main
95 mode of the YubiKey is entering a one time password (or a strong
106 static password) by acting as a USB HID device, but there are
11 things one can do with bi-directional communication.
7 things one can do with bi-directional communication:
128
13 1) Configuration. The yubikey_config class should be a feature-
9 1. Configuration. The yubikey_config class should be a feature-
1410 wise complete implementation of everything that can be
1511 configured on YubiKeys version 1.3 to 2.2 (besides deprecated
1612 functions in YubiKey 1.x).
17 See examples/configure_nist_test_key for an example.
13 See `examples/configure_nist_test_key` for an example.
1814
19 2) Challenge-response. YubiKey 2.2 supports HMAC-SHA1 or Yubico
15 2. Challenge-response. YubiKey 2.2 supports HMAC-SHA1 or Yubico
2016 challenge-response operations.
21 See examples/nist_challenge_response for an example.
17 See `examples/nist_challenge_response` for an example.
18
19 This library makes it easy to use these two features.
2220
2321 === Example
2422 Here is a trivial usage example :
4038 ----
4139
4240 === Installation
43 python-yubico is installable via pip:
4441
45 $ pip install yubico-python
46
47 Or, directly from the source package in the standard-python way:
48
49 $ cd python-yubico-$ver
50 $ python setup.py install
51
52 This requires the python-setuptools (well, the package is called
53 that in Debian/Ubuntu). You will also need the Python USB package
54 from http://pyusb.berlios.de/ - package called python-usb in
55 Debian/Ubuntu. Note that while both the 0.4 branch and the 1.0
56 branch are supported, the older 0.4 branch doesn't support
57 re-attaching the kernel device driver on close, which will leave
58 the YubiKey in a state where it is unable to output OTPs until it
59 has been unplugged and plugged back in again.
60
42 ==== Using the Ubuntu/Debian package manager
6143 If you use a recent Ubuntu release, you should be able to install
6244 python-yubico with these commands :
6345
6749
6850 The Launchpad PPA key generated for our packages is 32CBA1A9.
6951
52 ==== Using Pip
53 python-yubico is installable via pip:
54
55 $ pip install python-yubico
56
57 Or, directly from the source package in the standard Python way:
58
59 $ cd python-yubico-$ver
60 $ python setup.py install
61
62 This requires the `python-setuptools` package. You will also need
63 http://walac.github.io/pyusb[PyUSB], called python-usb in
64 Debian/Ubuntu. `pyusb` is available on PyPI and may be installed
65 with pip: `pip install --pre pyusb` The --pre command-line option
66 indicates that pre-releases of `pyusb` may also be searched (only
67 pre-releases of `pyusb` are available on PyPI, and pip skips
68 pre-releases by default). Note that while both the 0.4 branch and
69 the 1.0 branch are supported, the older 0.4 branch doesn't support
70 re-attaching the kernel device driver on close, which will leave
71 the YubiKey in a state where it is unable to output OTPs until it
72 has been unplugged and plugged back in again.
73
74 ==== On Windows
7075 If you use Windows, you will require a PyUSB backend. Python-yubico
71 has been tested with http://libusbx.org/ and confirmed working,
76 has been tested with http://libusbx.org[libusbx] and confirmed working,
7277 without the need for replacing the device driver.
78
79 === License
80 Copyright (c) Yubico AB.
81 Licensed under the BSD 2-clause license.
82 See the file COPYING for full licence statement.
00 Metadata-Version: 1.1
11 Name: python-yubico
2 Version: 1.2.2
2 Version: 1.2.3
33 Summary: Python code for talking to Yubico's YubiKeys
44 Home-page: https://github.com/Yubico/python-yubico
55 Author: Yubico Open Source Maintainers
1919 # Copyright (c) 2010, 2011, 2012 Yubico AB
2020 # See the file COPYING for licence statement.
2121
22 __version__ = "1.2.2"
22 __version__ = "1.2.3"
2323
2424 __all__ = [
2525 # classes
2525 import struct
2626 import time
2727 import sys
28 import usb
2829
2930 # Various USB/HID parameters
30 _USB_TYPE_CLASS = (0x01 << 5)
31 _USB_RECIP_INTERFACE = 0x01
32 _USB_ENDPOINT_IN = 0x80
33 _USB_ENDPOINT_OUT = 0x00
34
35 _HID_GET_REPORT = 0x01
36 _HID_SET_REPORT = 0x09
37
38 _USB_TIMEOUT_MS = 100
31 _USB_TYPE_CLASS = (0x01 << 5)
32 _USB_RECIP_INTERFACE = 0x01
33 _USB_ENDPOINT_IN = 0x80
34 _USB_ENDPOINT_OUT = 0x00
35
36 _HID_GET_REPORT = 0x01
37 _HID_SET_REPORT = 0x09
38
39 _USB_TIMEOUT_MS = 2000
3940
4041 # from ykcore_backend.h
41 _FEATURE_RPT_SIZE = 8
42 _REPORT_TYPE_FEATURE = 0x03
42 _FEATURE_RPT_SIZE = 8
43 _REPORT_TYPE_FEATURE = 0x03
4344 # from ykdef.h
44 _YUBICO_VID = 0x1050
45 _YUBIKEY_PID = 0x0010
46 _NEO_OTP_PID = 0x0110
47 _NEO_OTP_CCID_PID = 0x0111
45 _YUBICO_VID = 0x1050
46 _YUBIKEY_PID = 0x0010
47 _NEO_OTP_PID = 0x0110
48 _NEO_OTP_CCID_PID = 0x0111
49 _NEO_OTP_U2F_PID = 0x0114
50 _NEO_OTP_U2F_CCID_PID = 0x0116
51
52 _YK4_OTP_PID = 0x0401
53 _YK4_OTP_U2F_PID = 0x0403
54 _YK4_OTP_CCID_PID = 0x0405
55 _YK4_OTP_U2F_CCID_PID = 0x0407
56
57 _PLUS_U2F_OTP_PID = 0x0410
58
59 _YK_PIDS = [
60 _YUBIKEY_PID,
61 _NEO_OTP_PID,
62 _NEO_OTP_CCID_PID,
63 _NEO_OTP_U2F_PID,
64 _NEO_OTP_U2F_CCID_PID,
65 _YK4_OTP_PID,
66 _YK4_OTP_U2F_PID,
67 _YK4_OTP_CCID_PID,
68 _YK4_OTP_U2F_CCID_PID,
69 _PLUS_U2F_OTP_PID
70 ]
71
4872 # commands from ykdef.h
49 _SLOT_DEVICE_SERIAL = 0x10 # Device serial number
50 _SLOT_CHAL_OTP1 = 0x20 # Write 6 byte challenge to slot 1, get Yubico OTP response
51 _SLOT_CHAL_OTP2 = 0x28 # Write 6 byte challenge to slot 2, get Yubico OTP response
52 _SLOT_CHAL_HMAC1 = 0x30 # Write 64 byte challenge to slot 1, get HMAC-SHA1 response
53 _SLOT_CHAL_HMAC2 = 0x38 # Write 64 byte challenge to slot 2, get HMAC-SHA1 response
73 _SLOT_DEVICE_SERIAL = 0x10 # Device serial number
74 _SLOT_CHAL_OTP1 = 0x20 # Write 6 byte challenge to slot 1, get Yubico OTP response
75 _SLOT_CHAL_OTP2 = 0x28 # Write 6 byte challenge to slot 2, get Yubico OTP response
76 _SLOT_CHAL_HMAC1 = 0x30 # Write 64 byte challenge to slot 1, get HMAC-SHA1 response
77 _SLOT_CHAL_HMAC2 = 0x38 # Write 64 byte challenge to slot 2, get HMAC-SHA1 response
5478
5579 # dict used to select command for mode+slot in _challenge_response
5680 _CMD_CHALLENGE = {'HMAC': {1: _SLOT_CHAL_HMAC1, 2: _SLOT_CHAL_HMAC2},
286310 def _read(self):
287311 """ Read a USB HID feature report from the YubiKey. """
288312 request_type = _USB_TYPE_CLASS | _USB_RECIP_INTERFACE | _USB_ENDPOINT_IN
289 value = _REPORT_TYPE_FEATURE << 8 # apparently required for YubiKey 1.3.2, but not 2.2.x
313 value = _REPORT_TYPE_FEATURE << 8 # apparently required for YubiKey 1.3.2, but not 2.2.x
290314 recv = self._usb_handle.controlMsg(request_type,
291315 _HID_GET_REPORT,
292316 _FEATURE_RPT_SIZE,
334358 hexdump = yubico_util.hexdump(data, colorize=True)[:-1] # strip LF
335359 self._debug("WRITE : %s %s\n" % (hexdump, debug_str))
336360 request_type = _USB_TYPE_CLASS | _USB_RECIP_INTERFACE | _USB_ENDPOINT_OUT
337 value = _REPORT_TYPE_FEATURE << 8 # apparently required for YubiKey 1.3.2, but not 2.2.x
361 value = _REPORT_TYPE_FEATURE << 8 # apparently required for YubiKey 1.3.2, but not 2.2.x
338362 sent = self._usb_handle.controlMsg(request_type,
339363 _HID_SET_REPORT,
340364 data,
373397 sleep = 0.01
374398 # After six sleeps, we've slept 0.64 seconds.
375399 wait_num = (timeout * 2) - 1 + 6
376 resp_timeout = False # YubiKey hasn't indicated RESP_TIMEOUT (yet)
400 resp_timeout = False # YubiKey hasn't indicated RESP_TIMEOUT (yet)
377401 while not finished:
378402 this = self._read()
379403 flags = ord(this[7])
434458 if 'could not detach kernel driver from interface' in str(error):
435459 self._debug('The in-kernel-HID driver has already been detached\n')
436460 else:
437 self._debug("detachKernelDriver not supported!")
438
439 self._usb_handle.setConfiguration(1)
461 self._debug("detachKernelDriver not supported!\n")
462
463 try:
464 self._usb_handle.setConfiguration(1)
465 except usb.USBError:
466 self._debug("Unable to set configuration, ignoring...\n")
440467 self._usb_handle.claimInterface(self._usb_int)
441468 return True
442469
473500 devices = [d for bus in usb.busses() for d in bus.devices]
474501 for device in devices:
475502 if device.idVendor == _YUBICO_VID:
476 if device.idProduct in [_YUBIKEY_PID, _NEO_OTP_PID, _NEO_OTP_CCID_PID]:
503 if device.idProduct in _YK_PIDS:
477504 if skip == 0:
478505 return device
479506 skip -= 1