From 238225b49c52d44ab926c97c0f3bf9d93230d99a Mon Sep 17 00:00:00 2001
From: Nathaniel McCallum <npmccallum@redhat.com>
Date: Fri, 7 Nov 2014 10:47:43 -0500
Subject: [PATCH] Catch USBError during YubiKey location
https://fedorahosted.org/freeipa/ticket/4693
Reviewed-By: Martin Kosek <mkosek@redhat.com>
---
ipalib/plugins/otptoken_yubikey.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/ipalib/plugins/otptoken_yubikey.py b/ipalib/plugins/otptoken_yubikey.py
index 7095887ac7cdf5d4b7d0d30edc6cab0222246664..4c2594182c08a9de3f2f5861aac60b39a9ce022a 100644
--- a/ipalib/plugins/otptoken_yubikey.py
+++ b/ipalib/plugins/otptoken_yubikey.py
@@ -25,6 +25,7 @@ from ipalib.plugins.otptoken import otptoken
import os
+import usb.core
import yubico
__doc__ = _("""
@@ -81,8 +82,10 @@ class otptoken_add_yubikey(Command):
# Open the YubiKey
try:
yk = yubico.find_yubikey()
- except yubico.yubikey.YubiKeyError, e:
- raise NotFound(reason=_('No YubiKey found'))
+ except usb.core.USBError as e:
+ raise NotFound(reason="No YubiKey found: %s" % e.strerror)
+ except yubico.yubikey.YubiKeyError as e:
+ raise NotFound(reason=e.reason)
assert yk.version_num() >= (2, 1)
--
2.1.0