Aldaviva / AuthenticatorChooser

🗝️ Background program that skips the phone option and chooses the USB security key in Windows credential prompts.
Apache License 2.0
51 stars 1 forks source link

Error when dialog opens when the Alt+Tab window switcher is open #8

Open EchterAgo opened 1 month ago

EchterAgo commented 1 month ago

I keep seeing this sometimes. I think it happens if the security key dialog opens when the Alt+Tab switcher is open.

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at MS.Internal.Automation.UiaCoreApi.CheckError(Int32 hr)
   at AuthenticatorChooser.SecurityKeyChooser.chooseUsbSecurityKey(SystemWindow fidoPrompt)
   at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

************** Loaded Assemblies **************
System.Private.CoreLib
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Private.CoreLib.dll
----------------------------------------
AuthenticatorChooser
    Assembly Version: 0.1.0.0
    Location: 
----------------------------------------
System.Runtime
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Runtime.dll
----------------------------------------
mwinapi
    Assembly Version: 0.3.0.5
    Location: 
----------------------------------------
System.Windows.Forms
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Windows.Forms.dll
----------------------------------------
System.Windows.Forms.Primitives
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Windows.Forms.Primitives.dll
----------------------------------------
System.Console
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Console.dll
----------------------------------------
System.Diagnostics.TraceSource
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Diagnostics.TraceSource.dll
----------------------------------------
System.Collections
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Collections.dll
----------------------------------------
System.ComponentModel.Primitives
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.ComponentModel.Primitives.dll
----------------------------------------
System.Drawing.Primitives
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Drawing.Primitives.dll
----------------------------------------
System.Runtime.InteropServices
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Runtime.InteropServices.dll
----------------------------------------
System.Threading
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Threading.dll
----------------------------------------
System.Drawing.Common
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Drawing.Common.dll
----------------------------------------
System.Collections.Specialized
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Collections.Specialized.dll
----------------------------------------
Microsoft.Win32.Primitives
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\Microsoft.Win32.Primitives.dll
----------------------------------------
System.ComponentModel.EventBasedAsync
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.ComponentModel.EventBasedAsync.dll
----------------------------------------
System.Threading.Thread
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Threading.Thread.dll
----------------------------------------
System.Numerics.Vectors
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Numerics.Vectors.dll
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\Accessibility.dll
----------------------------------------
Microsoft.Win32.SystemEvents
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\Microsoft.Win32.SystemEvents.dll
----------------------------------------
System.Memory
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Memory.dll
----------------------------------------
Workshell.PE.Resources
    Assembly Version: 3.0.0.130
    Location: 
----------------------------------------
Workshell.PE
    Assembly Version: 3.0.0.130
    Location: 
----------------------------------------
System.Linq
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Linq.dll
----------------------------------------
System.Text.Encoding.Extensions
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Text.Encoding.Extensions.dll
----------------------------------------
UIAutomationClient
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\UIAutomationClient.dll
----------------------------------------
UIAutomationTypes
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\UIAutomationTypes.dll
----------------------------------------
ThrottleDebounce
    Assembly Version: 2.0.0.0
    Location: 
----------------------------------------
netstandard
    Assembly Version: 2.1.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\netstandard.dll
----------------------------------------
PresentationCore
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\PresentationCore.dll
----------------------------------------
WindowsBase
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\WindowsBase.dll
----------------------------------------
DirectWriteForwarder
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\DirectWriteForwarder.dll
----------------------------------------
System.Runtime.Extensions
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Runtime.Extensions.dll
----------------------------------------
System.Diagnostics.Debug
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Diagnostics.Debug.dll
----------------------------------------
System.Runtime.CompilerServices.VisualC
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Runtime.CompilerServices.VisualC.dll
----------------------------------------
System.Collections.NonGeneric
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Collections.NonGeneric.dll
----------------------------------------
System.ComponentModel
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.ComponentModel.dll
----------------------------------------
System.Threading.ThreadPool
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Threading.ThreadPool.dll
----------------------------------------
UIAutomationProvider
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\UIAutomationProvider.dll
----------------------------------------
System.Diagnostics.StackTrace
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Diagnostics.StackTrace.dll
----------------------------------------
UIAutomationClientSideProviders
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\UIAutomationClientSideProviders.dll
----------------------------------------
System.ComponentModel.TypeConverter
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.ComponentModel.TypeConverter.dll
----------------------------------------
System.Runtime.Loader
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Runtime.Loader.dll
----------------------------------------
System.Reflection.Metadata
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Reflection.Metadata.dll
----------------------------------------
System.Collections.Immutable
    Assembly Version: 8.0.0.0
    Location: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Collections.Immutable.dll
----------------------------------------

************** JIT Debugging **************
Aldaviva commented 1 month ago

Interesting, I will try to reproduce that and figure out how to fix it.

EchterAgo commented 1 month ago

I noticed that I wasn't running the latest version yet, I have upgraded now and will see if the issue happens again. I noticed it occasionally with the version from June.

Aldaviva commented 1 month ago

So far I haven't gotten AuthenticatorChooser to crash, but I have gotten AuthenticatorChooser to move the dialog box to the top-left corner of the screen if the dialog opens while the Alt+Tab window is open. Even when AuthenticatorChooser isn't running, opening a credentials dialog while the Alt+Tab window is open seems to frequently cause both the credentials window and Alt+Tab windows to become invisible and frozen, requiring you to kill CredentialsUIHost.exe to proceed, but sometimes that's insufficient and Alt+Tab is still invisible and frozen after that, at which point you have to restart explorer.exe using Task Manager's Restart Task or by just killing it.

I will keep working on this and also send you a build that has logging and line numbers to get more detailed information.

Testing notes

To easily get a WebAuthn dialog box to appear when I want, I am following these steps.

  1. Go to https://webauthn.io
  2. In the browser Developer Tools console, run
    setTimeout(() => document.getElementById("login-button").click(), 1000);
Aldaviva commented 1 month ago

The Alt+Tab window has class XamlExplorerHostIslandWindow and title Task Switching from process explorer.exe. (The old 95/NT CoolSwitch is from csrss.exe and you can trigger it with Alt+Alt+Tab).

Aldaviva commented 1 month ago

To make issues easier to debug, I should also

Aldaviva commented 1 month ago

Here is a development build with the following changes.

AuthenticatorChooser.zip

EchterAgo commented 4 weeks ago

It seems that getUserLocaleId throws for me on startup:

---------------------------
AuthenticatorChooser
---------------------------
Uncaught exception: System.TypeInitializationException: The type initializer for 'AuthenticatorChooser.I18N' threw an exception.

 ---> System.Security.SecurityException: Requested registry access is not allowed.

   at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)

   at Microsoft.Win32.Registry.GetValue(String keyName, String valueName, Object defaultValue)

   at AuthenticatorChooser.I18N.getUserLocaleId(Boolean currentUser) in /_/AuthenticatorChooser/I18N.cs:line 83

   at AuthenticatorChooser.I18N..cctor() in /_/AuthenticatorChooser/I18N.cs:line 30

   --- End of inner exception stack trace ---

   at AuthenticatorChooser.I18N.getUserLocaleId(Boolean currentUser) in /_/AuthenticatorChooser/I18N.cs:line 83

   at AuthenticatorChooser.Startup.OnExecute() in /_/AuthenticatorChooser/Startup.cs:line 52
---------------------------
OK   
---------------------------

I also see the same when using shell to query the value:

C:\Users\axel>reg query "HKEY_USERS\S-1-5-20\Control Panel\International"
ERROR: Access is denied.
Aldaviva commented 4 weeks ago

Thanks, I'll find another way to read that. I must not have tested with the right permissions.


Note to self: try https://learn.microsoft.com/en-us/powershell/module/international/get-winsystemlocale?view=windowsserver2022-ps

Aldaviva commented 4 weeks ago

Here is a fixed version that fetches the system locale using a Windows API call instead of a registry read on a different user's hive. Tested on Windows 11 23H2 with UAC turned all the way up.

AuthenticatorChooser.zip