Yubico / python-yubico

Python code to talk to YubiKeys
https://developers.yubico.com/python-yubico/
BSD 2-Clause "Simplified" License
229 stars 33 forks source link

Timeout when calling serial() #26

Closed the2nd closed 9 years ago

the2nd commented 9 years ago

Hi, I am currently implementing yubikey support (HMAC-SHA1) in OTPme (www.otpme.org). My current implementation works well with the OTPme PAM module if the connected yubikey has at least one slot configured for HMAC-SHA1. But when i call the serial() method with a yubikey that has no slot configured for HMA-SHA1 i always get a timeout when trying to get the serial:

Code: YK = yubico.find_yubikey(debug=debug) print("Version : %s " % YK.version()) print("Serial : %i" % YK.serial())

ERROR: Timed out waiting for YubiKey to set status 0x40

Is this by design or a bug?

My intention is to get the yubikey serial to identify it and decide if i should try challenge/response with the connected yubikey or not. It would be great if the serial() method would work independently of the slot configuration to prevent a delay when logging in with a yubikey connected that does not have HMAC-SHA1 configured (e.g. to login via HOTP).

regards the2nd

dainnilsson commented 9 years ago

There's a flag which controls if the serial can be read out using the API or not, called SERIAL_API_VISIBLE. If it is not set in either of the slots, the serial is not readable, with the exception of when both slots are empty, in which case the serial is readable. Make sure to set this flag when configuring a lot to ensure that the serial() method works.

the2nd commented 9 years ago

Thank added it to my deployment tool :)

Torxed commented 3 years ago

For reference, if calling token.serial() to quickly, the hardware will timeout as well causing this issue. Either you time.sleep your way around it or make sure your code only calls it once and cache the results : )