-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
using ManagedWinapi.Windows; | ||
using System.Windows.Automation; | ||
|
||
namespace AuthenticatorChooser; | ||
|
||
public static class Extensions { | ||
|
||
public static IntPtr toHwnd(this AutomationElement element) { | ||
return new IntPtr(element.Current.NativeWindowHandle); | ||
} | ||
|
||
public static SystemWindow toSystemWindow(this AutomationElement element) { | ||
return new SystemWindow(element.toHwnd()); | ||
} | ||
|
||
public static AutomationElement toAutomationElement(this SystemWindow window) { | ||
return AutomationElement.FromHandle(window.HWnd); | ||
} | ||
|
||
public static IEnumerable<AutomationElement> children(this AutomationElement parent) { | ||
return parent.FindAll(TreeScope.Children, Condition.TrueCondition).Cast<AutomationElement>(); | ||
} | ||
|
||
/// <summary>Remove null values.</summary> | ||
/// <returns>Input enumerable with null values removed.</returns> | ||
public static IEnumerable<T> Compact<T>(this IEnumerable<T?> source) where T: class { | ||
return source.Where(item => item != null)!; | ||
} | ||
|
||
/// <summary>Remove null values.</summary> | ||
/// <returns>Input enumerable with null values removed.</returns> | ||
public static IEnumerable<T> Compact<T>(this IEnumerable<T?> source) where T: struct { | ||
return (IEnumerable<T>) source.Where(item => item != null); | ||
} | ||
|
||
using ManagedWinapi.Windows; | ||
using System.Windows.Automation; | ||
|
||
namespace AuthenticatorChooser; | ||
|
||
public static class Extensions { | ||
|
||
public static IntPtr toHwnd(this AutomationElement element) { | ||
return new IntPtr(element.Current.NativeWindowHandle); | ||
} | ||
|
||
public static SystemWindow toSystemWindow(this AutomationElement element) { | ||
return new SystemWindow(element.toHwnd()); | ||
} | ||
|
||
public static AutomationElement toAutomationElement(this SystemWindow window) { | ||
return AutomationElement.FromHandle(window.HWnd); | ||
} | ||
|
||
public static IEnumerable<AutomationElement> children(this AutomationElement parent) { | ||
return parent.FindAll(TreeScope.Children, Condition.TrueCondition).Cast<AutomationElement>(); | ||
} | ||
|
||
/// <summary>Remove null values.</summary> | ||
/// <returns>Input enumerable with null values removed.</returns> | ||
public static IEnumerable<T> Compact<T>(this IEnumerable<T?> source) where T: class { | ||
return source.Where(item => item != null)!; | ||
} | ||
|
||
/// <summary>Remove null values.</summary> | ||
/// <returns>Input enumerable with null values removed.</returns> | ||
public static IEnumerable<T> Compact<T>(this IEnumerable<T?> source) where T: struct { | ||
return (IEnumerable<T>) source.Where(item => item != null); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,58 @@ | ||
using AuthenticatorChooser.WindowOpening; | ||
using ManagedWinapi.Windows; | ||
using System.Windows.Forms; | ||
|
||
namespace AuthenticatorChooser; | ||
|
||
internal static class Program { | ||
|
||
[STAThread] | ||
public static void Main() { | ||
Application.SetCompatibleTextRenderingDefault(false); | ||
Application.EnableVisualStyles(); | ||
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2); | ||
|
||
using WindowOpeningListener windowOpeningListener = new WindowOpeningListenerImpl(); | ||
windowOpeningListener.windowOpened += (_, window) => SecurityKeyChooser.chooseUsbSecurityKey(window); | ||
|
||
foreach (SystemWindow fidoPromptWindow in SystemWindow.FilterToplevelWindows(SecurityKeyChooser.isFidoPromptWindow)) { | ||
SecurityKeyChooser.chooseUsbSecurityKey(fidoPromptWindow); | ||
} | ||
|
||
_ = I18N.getStrings(I18N.Key.SMARTPHONE); // ensure localization is loaded eagerly | ||
|
||
Application.Run(); | ||
} | ||
|
||
using AuthenticatorChooser.WindowOpening; | ||
using ManagedWinapi.Windows; | ||
using Microsoft.Win32; | ||
using System.Security.Principal; | ||
using System.Windows.Forms; | ||
|
||
namespace AuthenticatorChooser; | ||
|
||
internal static class Program { | ||
|
||
private const string PROGRAM_NAME = nameof(AuthenticatorChooser); | ||
|
||
private static readonly IEqualityComparer<string> CASE_INSENSITIVE_COMPARER = StringComparer.InvariantCultureIgnoreCase; | ||
|
||
[STAThread] | ||
public static int Main(string[] args) { | ||
Application.SetCompatibleTextRenderingDefault(false); | ||
Application.EnableVisualStyles(); | ||
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2); | ||
|
||
if (args.Intersect(["--help", "/help", "-h", "/h", "-?", "/?"], CASE_INSENSITIVE_COMPARER).Any()) { | ||
string processFilename = Path.GetFileName(Environment.ProcessPath)!; | ||
MessageBox.Show( | ||
$""" | ||
{processFilename} | ||
Runs this program in the background normally, waiting for FIDO credentials dialog boxes to open and choosing the Security Key option each time. | ||
{processFilename} --autostart-on-logon | ||
Registers this program to start automatically every time the current user logs on to Windows. | ||
{processFilename} --help | ||
Shows usage. | ||
For more information, see https://github.com/Aldaviva/{PROGRAM_NAME} | ||
(press Ctrl+C to copy this message) | ||
""", $"{PROGRAM_NAME} usage", MessageBoxButtons.OK, MessageBoxIcon.Information); | ||
} else if (args.Contains("--autostart-on-logon", CASE_INSENSITIVE_COMPARER)) { | ||
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", PROGRAM_NAME, Environment.ProcessPath!); | ||
} else { | ||
using Mutex singleInstanceLock = new(true, $@"Local\{PROGRAM_NAME}_{WindowsIdentity.GetCurrent().User?.Value}", out bool isOnlyInstance); | ||
if (!isOnlyInstance) return 1; | ||
|
||
using WindowOpeningListener windowOpeningListener = new WindowOpeningListenerImpl(); | ||
windowOpeningListener.windowOpened += (_, window) => SecurityKeyChooser.chooseUsbSecurityKey(window); | ||
|
||
foreach (SystemWindow fidoPromptWindow in SystemWindow.FilterToplevelWindows(SecurityKeyChooser.isFidoPromptWindow)) { | ||
SecurityKeyChooser.chooseUsbSecurityKey(fidoPromptWindow); | ||
} | ||
|
||
_ = I18N.getStrings(I18N.Key.SMARTPHONE); // ensure localization is loaded eagerly | ||
|
||
Application.Run(); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
} |
30 changes: 15 additions & 15 deletions
30
AuthenticatorChooser/Properties/PublishProfiles/FolderProfile.pubxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project> | ||
<PropertyGroup> | ||
<Configuration>Release</Configuration> | ||
<Platform>Any CPU</Platform> | ||
<PublishDir>bin\Release\net8.0-windows\win-x64\publish\</PublishDir> | ||
<PublishProtocol>FileSystem</PublishProtocol> | ||
<_TargetId>Folder</_TargetId> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
<SelfContained>false</SelfContained> | ||
<PublishSingleFile>true</PublishSingleFile> | ||
<PublishReadyToRun>false</PublishReadyToRun> | ||
</PropertyGroup> | ||
--> | ||
<Project> | ||
<PropertyGroup> | ||
<Configuration>Release</Configuration> | ||
<Platform>Any CPU</Platform> | ||
<PublishDir>bin\Release\net8.0-windows\win-x64\publish\</PublishDir> | ||
<PublishProtocol>FileSystem</PublishProtocol> | ||
<_TargetId>Folder</_TargetId> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
<SelfContained>false</SelfContained> | ||
<PublishSingleFile>true</PublishSingleFile> | ||
<PublishReadyToRun>false</PublishReadyToRun> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters