Skip to content

Commit

Permalink
Merge pull request #2 from ibigbug/fix-webauthn
Browse files Browse the repository at this point in the history
fix webauthn by tracking active window
  • Loading branch information
ibigbug authored Jun 22, 2019
2 parents e278781 + 404396a commit 9714ff7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 17 deletions.
6 changes: 6 additions & 0 deletions NativeBridge/Bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ PWCHAR GetInterfaceDevicePath()

deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

printf("\nList of Toaster Device Interfaces\n");
printf("---------------------------------\n");

do
{
if (SetupDiEnumDeviceInterfaces(
Expand Down Expand Up @@ -88,6 +91,9 @@ PWCHAR GetInterfaceDevicePath()
free(deviceInterfaceDetailData);
return NULL;
}

printf("%d) %s\n", i,
deviceInterfaceDetailData->DevicePath);
}
else if (GetLastError() != ERROR_NO_MORE_ITEMS)
{
Expand Down
2 changes: 0 additions & 2 deletions SoftU2FDaemon/Driver/driver-install.ps1

This file was deleted.

52 changes: 42 additions & 10 deletions SoftU2FDaemon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -27,7 +28,6 @@ class App : Form, INotifySender
{
private NotifyIcon _trayIcon;
private ContextMenu _trayMenu;
private IContainer components;
private CancellationTokenSource _cancellation;

private IServiceProvider _serviceProvider;
Expand Down Expand Up @@ -57,6 +57,18 @@ public App()
InitializeBackgroundDaemon();
}

#region Application LifeCycle

IntPtr lastActiveWin = IntPtr.Zero;

[DllImport("user32.dll", ExactSpelling = true)]
static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
#endregion

#region Application Initialization

private void Restart()
Expand Down Expand Up @@ -128,22 +140,27 @@ private void InitializeTrayIcon()
_trayMenu.MenuItems.Add("-");
_trayMenu.MenuItems.Add("Exit", (sender, args) => Application.Exit());

components = new Container();

_trayIcon = new NotifyIcon(components)
_trayIcon = new NotifyIcon
{
Text = "SoftU2F Daemon",
ContextMenu = _trayMenu,
Icon = new Icon("tray.ico"),
Visible = true
Visible = true,
};

_trayIcon.BalloonTipClicked += (sender, args) =>
{
if (lastActiveWin != IntPtr.Zero)
SetForegroundWindow(lastActiveWin);

_notificationOpen = false;
_userPresenceCallback?.Invoke(true);
};
_trayIcon.BalloonTipShown += (sender, args) => _notificationOpen = true;
_trayIcon.BalloonTipShown += (sender, args) =>
{
_notificationOpen = true;
lastActiveWin = GetForegroundWindow();
};
_trayIcon.BalloonTipClosed += (sender, args) => _notificationOpen = false;
}

Expand Down Expand Up @@ -202,18 +219,33 @@ protected override void OnLoad(EventArgs e)
base.OnLoad(e);
}

#endregion

#region IDisposable

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private bool disposed = false;
protected override void Dispose(bool disposing)
{
if (disposed) return;
if (disposing)
{
components?.Dispose();
}

_cancellation.Cancel();

_cancellation.Cancel();
}
base.Dispose(disposing);
}

~App()
{
Dispose(true);
}

#endregion

#region UserPresence
Expand Down
5 changes: 3 additions & 2 deletions SoftU2FDaemon/SoftU2FDaemon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0;netstandard2.0;netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Resources\key.ico</ApplicationIcon>
<ApplicationIcon>Resources\tray.ico</ApplicationIcon>
<StartupObject />
<Authors>ibigbug</Authors>
<Company>Watfaq</Company>
Expand All @@ -18,6 +18,7 @@

<PropertyGroup>
<DebugType Condition=" '$(Configuration)' == 'Release' ">None</DebugType>
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion SoftU2FDriver/Device.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ CreateRawPdo(
WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;

DECLARE_CONST_UNICODE_STRING(deviceId, SoftU2F_DEVICE_ID);
DECLARE_CONST_UNICODE_STRING(deviceLocation, L"HID Injector Sample\0");
DECLARE_CONST_UNICODE_STRING(deviceLocation, L"SoftU2F Communicator\0");
DECLARE_CONST_UNICODE_STRING(SDDL_MY_PERMISSIONS, L"D:P(A;; GA;;; SY)(A;; GA;;; BA)(A;; GA;;; WD)");
DECLARE_UNICODE_STRING_SIZE(buffer, MAX_ID_LEN);

Expand Down
4 changes: 2 additions & 2 deletions SoftU2FDriver/Public.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Module Name:

// {DC3DE777-BC7E-4063-86C9-69422E319AF7}
DEFINE_GUID(GUID_DEVINTERFACE_SOFTU2F_FILTER,
0xdc3de777, 0xbc7e, 0x4063, 0x86, 0xc9, 0x69, 0x42, 0x2e, 0x31, 0x9a, 0xf7);
0xdc3de777, 0xbc7e, 0x4063, 0x86, 0xc9, 0x69, 0x42, 0x2e, 0x31, 0x9a, 0xf7) ;

// {600C7C9E-3DD0-4521-B931-4398F48A3C5D}
DEFINE_GUID (GUID_BUS_SoftU2F,
Expand All @@ -37,7 +37,7 @@ DEFINE_GUID (GUID_DEVCLASS_SoftU2F,
#define MILLISECOND 10000
#define RELATIVE_MILLISECOND (-MILLISECOND)

#define SoftU2F_DEVICE_ID L"{600C7C9E-3DD0-4521-B931-4398F48A3C5D}\\SoftU2F\0"
#define SoftU2F_DEVICE_ID L"SoftU2F\\{600C7C9E-3DD0-4521-B931-4398F48A3C5D}\0"
#define MAX_ID_LEN 128

#define IOCTL_INDEX 0x800
Expand Down
Binary file modified U2FLib/NativeBridge.dll
Binary file not shown.

0 comments on commit 9714ff7

Please sign in to comment.