Yubico / Yubico.NET.SDK

A YubiKey SDK for .NET developers
Apache License 2.0
99 stars 47 forks source link

"No Yubikey interface available" when enabling All interfaces #42

Closed steven-keller closed 1 year ago

steven-keller commented 1 year ago

I'm using the Yubico.Core and Yubico.Yubikey Nuget packages for setting/removing Lock Codes and add/remove NFC/USB Capabilities. The SetEnabledUSBCapabilities and SetEnabledNFCCapabilities methods work fine when starting with a Yubikey that initially has all capabilities enabled and then removing all but the FIDO2 NFC/USB capabilities. However, when I try to re-enable "All" capabilities on that Yubikey, I get "There is no YubiKey interface available to communicate with the requested application".

They YKMan.exe utility and the YKMan-GUI do not have this problem, so it's certainly possible to do this using other means. Is there some method I need to run prior to the lines of code below, or is this a bug in the SDK?

device.SetEnabledNfcCapabilities(YubiKeyCapabilities.All); device.SetEnabledUSBCapabilities(YubiKeyCapabilities.All);

GregDomzalski commented 1 year ago

Is this on Windows? If so, you need to run your code in an elevated process.

Windows prevents unprivileged access to any CTAP devices.

steven-keller commented 1 year ago

Yes, I'm definitely running the code as Elevated (Windows 11).

From: Greg Domzalski @.> Sent: Tuesday, March 21, 2023 12:59 PM To: Yubico/Yubico.NET.SDK @.> Cc: Steve Keller @.>; Author @.> Subject: Re: [Yubico/Yubico.NET.SDK] "No Yubikey interface available" when enabling All interfaces (Issue #42)

Is this on Windows? If so, you need to run your code in an elevated process.

Windows prevents unprivileged access to any CTAP devices.

-

GregDomzalski commented 1 year ago

Huh, OK - then yes, that is definitely very curious.

Would you mind enabling logging and sending that our way? This example uses Serilog, but it is possible to use different providers so long as they can integrate with the Microsoft.Extensions.Logging framework (which most can).

            using var log = new LoggerConfiguration()
                .Enrich.With(new ThreadIdEnricher())
                .WriteTo.Console(
                    outputTemplate: "[{Level}] ({ThreadId})  {Message}{NewLine}{Exception}")
                .CreateLogger();

            // This is the line that actually enables the logger for the SDK. So long as LoggerFactory
            // is set to something that properly implements the interface, we should be good to go.
            Core.Logging.Log.LoggerFactory = LoggerFactory.Create(
                builder => builder
                    .AddSerilog(log)
                    .AddFilter(level => level >= LogLevel.Information));
GregDomzalski commented 1 year ago

Hey @steven-keller - were you able to get logging turned on? Did that show any errors or warnings that might be helpful?

steven-keller commented 1 year ago

Hi, @GregDomzalski . I started to do this last week, but it's a bit of a learning curve with Serilog/Microsoft.Extensions.Logging which I've not used before. I couldn't get "Console" in the WriteTo.Console(..... code segment to be recognized as a valid method...maybe missing some other Nuget package. I was originally using a WinForms app, but I'll try later this week to get it working in a Console app. Thanks for the follow up!

GregDomzalski commented 1 year ago

Yes, sorry about that. I just realized that we don't really have a good writeup in our documentation. We ought to correct that.

I believe you would need the following packages:

I hope that helps!

GregDomzalski commented 1 year ago

Hey @steven-keller - any update on your side? I was never able to reproduce this on my end. Are you still encountering this issue?

GregDomzalski commented 1 year ago

Closing this issue. Feel free to re-open it if you are still encountering the issue.