Yubico / yubikey-manager

Python library and command line tool for configuring any YubiKey over all USB interfaces.
https://developers.yubico.com/yubikey-manager/
BSD 2-Clause "Simplified" License
875 stars 125 forks source link

yubikey-manager/doc/Library_Usage.adoc - Error in document #431

Closed wagner-robert closed 3 years ago

wagner-robert commented 3 years ago

Steps to reproduce

[Please explain what you did when the bug appeared, and if and how you have been able to reproduce it.]

Using your code

Expected result

[What did you expect to happen when you did the above?]

Actual results and logs

[What actually happened?]

Other info

I was able to get around it using: for device, info in list_all_devices(): if info.version >= (5, 0, 0): # The info object provides details about the YubiKey

connection, , = connect_to_device(serial = info.serial, [SmartCardConnection])

        #connection, _, _ = connect_to_device([SmartCardConnection], serial=int(info.serial))
        x1=info.serial
        connection, _, _ = connect_to_device(x1, [SmartCardConnection])
        print("I found one"+str(info.serial)+" Device: "+str(device))

[Anything else you would like to add?]

dainnilsson commented 3 years ago

Thanks! I've pushed a fix for that. Both of these alternatives can be used: connect_to_device(serial=info.serial, connection_type=[SmartCardConnection]) connect_to_device(info.serial, [SmartCardConnection])

wagner-robert commented 2 years ago

Question? - The examples provides show a SmartCard connection. https://developers.yubico.com/yubikey-manager/Library_Usage.html Library Usage - developers.yubico.comhttps://developers.yubico.com/yubikey-manager/Library_Usage.html The first step you’ll likely want to do is to establish a Session with a YubiKey Application. Depending on which Application you intend to access, you’ll need to establish a specific type of Connection. developers.yubico.com How should we handle instances where the PIV and/or OTP USB interfaces has been disabled? Multiple tries?

for device, info in list_all_devices():
    if info.version == (5, 1, 2):  # The info object provides details about the YubiKey
        connection, _, _ = connect_to_device(serial=info.serial, connection_types=[OtpConnection])    #v5 NFC
    else:
        connection, _, _ = connect_to_device(serial=info.serial, connection_types=[SmartCardConnection])  #V4,5 FIP
        #connection, _, _ = connect_to_device(serial=info.serial, connection_types=[SmartCardConnection])  #V4,5 FIPS
        #connection, _, _ = connect_to_device(serial=info.serial, connection_types=[OtpConnection])    #v5 NFC
    print("I found one: "+str(info.serial)+" Device: "+str(device))

Robert Wagner


From: Dain Nilsson @.> Sent: Monday, July 12, 2021 7:13 AM To: Yubico/yubikey-manager @.> Cc: Robert Wagner @.>; Author @.> Subject: Re: [Yubico/yubikey-manager] yubikey-manager/doc/Library_Usage.adoc - Error in document (#431)

Thanks! I've pushed a fix for that. Both of these alternatives can be used: connect_to_device(serial=info.serial, connection_type=[SmartCardConnection]) connect_to_device(info.serial, [SmartCardConnection])

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Yubico/yubikey-manager/issues/431#issuecomment-878192122, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AUY3JQFJ5MDAP5QIXUNBPJ3TXLE6TANCNFSM5AGSTREA.

dainnilsson commented 2 years ago

I'm not quite sure I understand what it is you are trying to do. If for instance the PIV (USB CCID) interface is disabled, you won't be able to open a SmartCardConnection, and you won't be able to do anything with the PIV application. What would you then intend to do with the YubiKey at that point?

You can check for a specific capability before attempting to access it through the info object, for example:

if CAPABILITY.PIV in info.config.enabled_capabilites[TRANSPORT.USB]:
    print("This YubiKey has PIV enabled over USB")
else:
    print("PIV is not enabled.")