Imported Upstream version 1.2.3
Dain Nilsson
9 years ago
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 | ||
0 | 30 | 2015-02-11 Dain Nilsson <dain@yubico.com> |
1 | 31 | |
2 | 32 | * 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 | ||
0 | 4 | * Version 1.2.2 (released 2015-02-11) |
1 | 5 | ** Fixed bug in yubikey-totp using wrong timestamp. |
2 | 6 | ** No longer require nose for setup, only for tests. |
0 | 0 | Metadata-Version: 1.1 |
1 | 1 | Name: python-yubico |
2 | Version: 1.2.2 | |
2 | Version: 1.2.3 | |
3 | 3 | Summary: Python code for talking to Yubico's YubiKeys |
4 | 4 | Home-page: https://github.com/Yubico/python-yubico |
5 | 5 | Author: Yubico Open Source Maintainers |
0 | 0 | == python-yubico |
1 | 1 | 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. | |
6 | 2 | |
7 | 3 | === Introduction |
8 | 4 | The YubiKey is a hardware token for authentication. The main |
9 | 5 | mode of the YubiKey is entering a one time password (or a strong |
10 | 6 | 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: | |
12 | 8 | |
13 | 1) Configuration. The yubikey_config class should be a feature- | |
9 | 1. Configuration. The yubikey_config class should be a feature- | |
14 | 10 | wise complete implementation of everything that can be |
15 | 11 | configured on YubiKeys version 1.3 to 2.2 (besides deprecated |
16 | 12 | 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. | |
18 | 14 | |
19 | 2) Challenge-response. YubiKey 2.2 supports HMAC-SHA1 or Yubico | |
15 | 2. Challenge-response. YubiKey 2.2 supports HMAC-SHA1 or Yubico | |
20 | 16 | 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. | |
22 | 20 | |
23 | 21 | === Example |
24 | 22 | Here is a trivial usage example : |
40 | 38 | ---- |
41 | 39 | |
42 | 40 | === Installation |
43 | python-yubico is installable via pip: | |
44 | 41 | |
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 | |
61 | 43 | If you use a recent Ubuntu release, you should be able to install |
62 | 44 | python-yubico with these commands : |
63 | 45 | |
67 | 49 | |
68 | 50 | The Launchpad PPA key generated for our packages is 32CBA1A9. |
69 | 51 | |
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 | |
70 | 75 | 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, | |
72 | 77 | 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. |
0 | 0 | Metadata-Version: 1.1 |
1 | 1 | Name: python-yubico |
2 | Version: 1.2.2 | |
2 | Version: 1.2.3 | |
3 | 3 | Summary: Python code for talking to Yubico's YubiKeys |
4 | 4 | Home-page: https://github.com/Yubico/python-yubico |
5 | 5 | Author: Yubico Open Source Maintainers |
19 | 19 | # Copyright (c) 2010, 2011, 2012 Yubico AB |
20 | 20 | # See the file COPYING for licence statement. |
21 | 21 | |
22 | __version__ = "1.2.2" | |
22 | __version__ = "1.2.3" | |
23 | 23 | |
24 | 24 | __all__ = [ |
25 | 25 | # classes |
25 | 25 | import struct |
26 | 26 | import time |
27 | 27 | import sys |
28 | import usb | |
28 | 29 | |
29 | 30 | # 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 | |
39 | 40 | |
40 | 41 | # from ykcore_backend.h |
41 | _FEATURE_RPT_SIZE = 8 | |
42 | _REPORT_TYPE_FEATURE = 0x03 | |
42 | _FEATURE_RPT_SIZE = 8 | |
43 | _REPORT_TYPE_FEATURE = 0x03 | |
43 | 44 | # 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 | ||
48 | 72 | # 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 | |
54 | 78 | |
55 | 79 | # dict used to select command for mode+slot in _challenge_response |
56 | 80 | _CMD_CHALLENGE = {'HMAC': {1: _SLOT_CHAL_HMAC1, 2: _SLOT_CHAL_HMAC2}, |
286 | 310 | def _read(self): |
287 | 311 | """ Read a USB HID feature report from the YubiKey. """ |
288 | 312 | 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 | |
290 | 314 | recv = self._usb_handle.controlMsg(request_type, |
291 | 315 | _HID_GET_REPORT, |
292 | 316 | _FEATURE_RPT_SIZE, |
334 | 358 | hexdump = yubico_util.hexdump(data, colorize=True)[:-1] # strip LF |
335 | 359 | self._debug("WRITE : %s %s\n" % (hexdump, debug_str)) |
336 | 360 | 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 | |
338 | 362 | sent = self._usb_handle.controlMsg(request_type, |
339 | 363 | _HID_SET_REPORT, |
340 | 364 | data, |
373 | 397 | sleep = 0.01 |
374 | 398 | # After six sleeps, we've slept 0.64 seconds. |
375 | 399 | 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) | |
377 | 401 | while not finished: |
378 | 402 | this = self._read() |
379 | 403 | flags = ord(this[7]) |
434 | 458 | if 'could not detach kernel driver from interface' in str(error): |
435 | 459 | self._debug('The in-kernel-HID driver has already been detached\n') |
436 | 460 | 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") | |
440 | 467 | self._usb_handle.claimInterface(self._usb_int) |
441 | 468 | return True |
442 | 469 | |
473 | 500 | devices = [d for bus in usb.busses() for d in bus.devices] |
474 | 501 | for device in devices: |
475 | 502 | 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: | |
477 | 504 | if skip == 0: |
478 | 505 | return device |
479 | 506 | skip -= 1 |