Skip to content
This repository was archived by the owner on Jun 9, 2022. It is now read-only.

Commit 75c0d9c

Browse files
authored
Merge branch 'master' into yubikey-nano-support
2 parents 7765424 + 0afd128 commit 75c0d9c

6 files changed

Lines changed: 27 additions & 12 deletions

File tree

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* Version 3.0.1 (released 2017-06-14)
2+
** Improved Python 3 compatibility.
3+
14
* Version 3.0.0 (released 2016-04-11)
25
** Added support for Python 3.3+.
36
** utils.rand_bytes() now sources bytes from os.urandom().

u2flib_host/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2626
# POSSIBILITY OF SUCH DAMAGE.
2727

28-
__version__ = "3.0.0"
28+
__version__ = "3.0.2-dev0"

u2flib_host/authenticate.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def parse_args():
103103
def main():
104104
args = parse_args()
105105

106-
facet = text_type(args.facet, sys.stdin.encoding or sys.getdefaultencoding())
106+
facet = text_type(args.facet)
107107
if args.infile:
108108
with open(args.infile, 'r') as f:
109109
data = f.read()
@@ -112,8 +112,7 @@ def main():
112112
sys.stderr.write('Enter AuthenticateRequest JSON data...\n')
113113
data = sys.stdin.read()
114114

115-
params = json.loads(data, object_hook=u2str)
116-
115+
params = json.loads(data)
117116
if args.soft:
118117
from u2flib_host.soft import SoftU2FDevice
119118
devices = [SoftU2FDevice(args.soft)]

u2flib_host/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_supported_versions(self):
7272
"""
7373
if not hasattr(self, '_versions'):
7474
try:
75-
self._versions = [self.send_apdu(INS_GET_VERSION)]
75+
self._versions = [self.send_apdu(INS_GET_VERSION).decode()]
7676
except exc.APDUError as e:
7777
# v0 didn't support the instruction.
7878
self._versions = ['v0'] if e.code == 0x6d00 else []

u2flib_host/hid_transport.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,28 @@
5959
# USB Commands
6060
CMD_INIT = 0x06
6161
CMD_WINK = 0x08
62+
CMD_PING = 0x01
6263
CMD_APDU = 0x03
64+
CMD_LOCK = 0x04
6365
U2FHID_YUBIKEY_DEVICE_CONFIG = U2F_VENDOR_FIRST
6466

6567
STAT_ERR = 0xbf
6668

67-
def list_devices():
69+
70+
def list_devices(dev_class=None):
71+
dev_class = dev_class or HIDDevice
6872
devices = []
6973
for d in hid.enumerate(0, 0):
7074
usage_page = d['usage_page']
7175
if usage_page == 0xf1d0 and d['usage'] == 1:
72-
devices.append(HIDDevice(d['path']))
76+
devices.append(dev_class(d['path']))
7377
# Usage page doesn't work on Linux
7478
elif (d['vendor_id'], d['product_id']) in DEVICES:
7579
device = HIDDevice(d['path'])
7680
try:
7781
device.open()
7882
device.close()
79-
devices.append(HIDDevice(d['path']))
83+
devices.append(dev_class(d['path']))
8084
except:
8185
pass
8286
return devices
@@ -136,6 +140,15 @@ def _do_send_apdu(self, apdu_data):
136140
def wink(self):
137141
self.call(CMD_WINK)
138142

143+
def ping(self, msg=b'Hello U2F'):
144+
resp = self.call(CMD_PING, msg)
145+
if resp != msg:
146+
raise exc.DeviceError("Incorrect PING readback")
147+
return resp
148+
149+
def lock(self, lock_time=10):
150+
self.call(CMD_LOCK, lock_time)
151+
139152
def _send_req(self, cid, cmd, data):
140153
size = len(data)
141154
bc_l = int2byte(size & 0xff)
@@ -160,7 +173,7 @@ def _read_resp(self, cid, cmd):
160173
resp_vals = _read_timeout(self.handle, HID_RPT_SIZE)
161174
resp = b''.join(int2byte(v) for v in resp_vals)
162175
if resp[:5] == cid + int2byte(STAT_ERR):
163-
raise U2FHIDError(byte2int(resp[6]))
176+
raise U2FHIDError(byte2int(resp[7]))
164177

165178
if not resp:
166179
raise exc.DeviceError("Invalid response from device!")
@@ -175,7 +188,7 @@ def _read_resp(self, cid, cmd):
175188
resp = b''.join(int2byte(v) for v in resp_vals)
176189
if resp[:4] != cid:
177190
raise exc.DeviceError("Wrong CID from device!")
178-
if byte2int(resp[4:5]) != seq & 0x7f:
191+
if byte2int(resp[4]) != seq & 0x7f:
179192
raise exc.DeviceError("Wrong SEQ from device!")
180193
seq += 1
181194
new_data = resp[5:min(5 + data_len, HID_RPT_SIZE)]

u2flib_host/register.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ def parse_args():
9595
def main():
9696
args = parse_args()
9797

98-
facet = text_type(args.facet, sys.stdin.encoding or sys.getdefaultencoding())
98+
facet = text_type(args.facet)
9999
if args.infile:
100100
with open(args.infile, 'r') as f:
101101
data = f.read()
102102
else:
103103
if sys.stdin.isatty():
104104
sys.stderr.write('Enter RegistrationRequest JSON data...\n')
105105
data = sys.stdin.read()
106-
params = json.loads(data, object_hook=u2str)
106+
params = json.loads(data)
107107

108108
if args.soft:
109109
from u2flib_host.soft import SoftU2FDevice

0 commit comments

Comments
 (0)