Skip to content

Commit

Permalink
Merge pull request #60 from Watfaq/unprotected-db
Browse files Browse the repository at this point in the history
Unprotected db
  • Loading branch information
ibigbug authored Mar 19, 2023
2 parents 570ea90 + fdab887 commit 3ae8af8
Show file tree
Hide file tree
Showing 17 changed files with 346 additions and 93 deletions.
2 changes: 1 addition & 1 deletion APDU/APDU.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion JustTest/JustTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net6.0-windows7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ We take the security of this project seriously. Report any security vulnerabilit

The app runs in the background. When a site loaded in a U2F-compatible browser attempts to register or authenticate with the software token, you'll see a notification asking you to accept or reject the request. You can experiment on [Yubico's U2F demo site](https://demo.yubico.com/u2f).

### Command Line Arguments
- *--db-unprotected* - this will save the key pair into a separated sqlite db without the DPAPI protection, this can be useful if you want to back up the db for some reasons. when enabled, the data will be saved in to `db.unprotected.sqlite`. You can find the databases under `$HOME\AppData\Roaming\SoftU2FDaemon`

### Registration

![Registration](https://user-images.githubusercontent.com/543405/59797397-e9ab4e80-9322-11e9-9f36-555b608f926d.png)
Expand Down
52 changes: 45 additions & 7 deletions SoftU2F.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "U2FLib", "U2FLib\U2FLib.csproj", "{A0BEBDF6-1D0D-4085-910F-60AE9111613E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoftU2FDaemon", "SoftU2FDaemon\SoftU2FDaemon.csproj", "{DA6EEE3B-38E8-414B-BDBF-AD3B80BC5950}"
ProjectSection(ProjectDependencies) = postProject
{54A914C2-7CE1-4F25-9722-8B90D5641689} = {54A914C2-7CE1-4F25-9722-8B90D5641689}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JustTest", "JustTest\JustTest.csproj", "{551530B9-2C88-430A-B669-06F481FBB658}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoftU2FDriverPackage", "SoftU2FDriverPackage\SoftU2FDriverPackage.vcxproj", "{B13752F9-1180-4716-9B4B-2D801305F15E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,17 +35,19 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|Any CPU.ActiveCfg = Debug|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|Any CPU.Build.0 = Debug|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|ARM.ActiveCfg = Debug|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|ARM64.ActiveCfg = Debug|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|x64.ActiveCfg = Release|x64
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|x64.Build.0 = Release|x64
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|x64.ActiveCfg = Release|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|x64.Build.0 = Release|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|x86.ActiveCfg = Debug|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Debug|x86.Build.0 = Debug|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|Any CPU.ActiveCfg = Release|x64
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|Any CPU.ActiveCfg = Release|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|Any CPU.Build.0 = Release|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|ARM.ActiveCfg = Release|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|ARM64.ActiveCfg = Release|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|x64.ActiveCfg = Release|x64
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|x64.Build.0 = Release|x64
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|x64.ActiveCfg = Release|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|x64.Build.0 = Release|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|x86.ActiveCfg = Release|Win32
{54A914C2-7CE1-4F25-9722-8B90D5641689}.Release|x86.Build.0 = Release|Win32
{011BE5F9-1916-4549-B307-779097C922AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -64,6 +71,7 @@ Global
{011BE5F9-1916-4549-B307-779097C922AF}.Release|x86.ActiveCfg = Release|Any CPU
{011BE5F9-1916-4549-B307-779097C922AF}.Release|x86.Build.0 = Release|Any CPU
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Debug|Any CPU.ActiveCfg = Debug|Win32
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Debug|Any CPU.Build.0 = Debug|Win32
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Debug|ARM.ActiveCfg = Debug|ARM
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Debug|ARM.Build.0 = Debug|ARM
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Debug|ARM.Deploy.0 = Debug|ARM
Expand All @@ -76,8 +84,8 @@ Global
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Debug|x86.ActiveCfg = Debug|Win32
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Debug|x86.Build.0 = Debug|Win32
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Debug|x86.Deploy.0 = Debug|Win32
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Release|Any CPU.ActiveCfg = Release|x64
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Release|Any CPU.Build.0 = Release|x64
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Release|Any CPU.ActiveCfg = Release|Win32
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Release|Any CPU.Build.0 = Release|Win32
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Release|ARM.ActiveCfg = Release|ARM
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Release|ARM.Build.0 = Release|ARM
{6480AC5C-E1DE-4855-B9EA-AFA0243EFE88}.Release|ARM.Deploy.0 = Release|ARM
Expand Down Expand Up @@ -150,6 +158,36 @@ Global
{551530B9-2C88-430A-B669-06F481FBB658}.Release|x64.Build.0 = Release|Any CPU
{551530B9-2C88-430A-B669-06F481FBB658}.Release|x86.ActiveCfg = Release|Any CPU
{551530B9-2C88-430A-B669-06F481FBB658}.Release|x86.Build.0 = Release|Any CPU
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|Any CPU.ActiveCfg = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|Any CPU.Build.0 = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|Any CPU.Deploy.0 = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|ARM.ActiveCfg = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|ARM.Build.0 = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|ARM.Deploy.0 = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|ARM64.ActiveCfg = Debug|ARM64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|ARM64.Build.0 = Debug|ARM64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|ARM64.Deploy.0 = Debug|ARM64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|x64.ActiveCfg = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|x64.Build.0 = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|x64.Deploy.0 = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|x86.ActiveCfg = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|x86.Build.0 = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Debug|x86.Deploy.0 = Debug|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|Any CPU.ActiveCfg = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|Any CPU.Build.0 = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|Any CPU.Deploy.0 = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|ARM.ActiveCfg = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|ARM.Build.0 = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|ARM.Deploy.0 = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|ARM64.ActiveCfg = Release|ARM64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|ARM64.Build.0 = Release|ARM64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|ARM64.Deploy.0 = Release|ARM64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|x64.ActiveCfg = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|x64.Build.0 = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|x64.Deploy.0 = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|x86.ActiveCfg = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|x86.Build.0 = Release|x64
{B13752F9-1180-4716-9B4B-2D801305F15E}.Release|x86.Deploy.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
40 changes: 32 additions & 8 deletions SoftU2FDaemon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

namespace SoftU2FDaemon
{
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Win32;
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Win32;
using U2FLib;
using U2FLib.Storage;

Expand All @@ -29,6 +29,11 @@ public App()
SetupApplication();
InitializeTrayIcon();
InitializeBackgroundDaemon();

if (DiagnoseMode)
{
tryOutNotification();
}
}

[STAThread]
Expand All @@ -48,6 +53,11 @@ public static void Main()

private static readonly string DBPath = Path.Combine(
BinFolder, "db.sqlite");
private static readonly string UnProtectedDBPath = Path.Combine(BinFolder, "db.unprotected.sqlite");

public static bool UnprotectedMode => Environment.GetCommandLineArgs().Contains("--db-unprotected");

public static bool DiagnoseMode => Environment.GetCommandLineArgs().Contains("--diagnose-mode");

#endregion

Expand Down Expand Up @@ -115,8 +125,17 @@ private void ConfigureServices(IServiceCollection service)
{
service.AddLogging();
service.AddSingleton<IU2FBackgroundTask, BackgroundTask>();
service.AddDbContext<AppDbContext>(options => { options.UseSqlite($"Filename={DBPath}"); });
Environment.SetEnvironmentVariable("DBPath", DBPath); // for DbContext outside container

if (UnprotectedMode)
{
service.AddDbContext<AppDbContext>(options => { options.UseSqlite($"Filename={UnProtectedDBPath}"); });
Environment.SetEnvironmentVariable("DBPath", UnProtectedDBPath); // for DbContext outside container
}
else
{
service.AddDbContext<AppDbContext>(options => { options.UseSqlite($"Filename={DBPath}"); });
Environment.SetEnvironmentVariable("DBPath", DBPath); // for DbContext outside container
}
}

#endregion
Expand All @@ -127,7 +146,7 @@ private void InitializeTrayIcon()
{
_trayMenu = new ContextMenu();

var item = new MenuItem {Text = @"Auto Start", Checked = AutoStart()};
var item = new MenuItem { Text = @"Auto Start", Checked = AutoStart() };
item.Click += OnAutoStartClick;
_trayMenu.Items.Add(item);

Expand Down Expand Up @@ -174,7 +193,7 @@ private void OnAutoStartClick(object sender, EventArgs e)
key?.SetValue(BinName, "\"" + Application.ExecutablePath + "\"");
}

var item = (MenuItem) sender;
var item = (MenuItem)sender;
item.Checked = !item.Checked;
}

Expand Down Expand Up @@ -255,11 +274,16 @@ private Action<bool> UserPresenceCallback
public void Send(string title, string message, Action<bool> userClicked)
{
if (_notificationOpen) return;
_trayIcon.ShowBalloonTip((int) TimeSpan.FromSeconds(10).TotalMilliseconds, title, message,
_trayIcon.ShowBalloonTip((int)TimeSpan.FromSeconds(10).TotalMilliseconds, title, message,
ToolTipIcon.Info);
UserPresenceCallback = userClicked;
}

private void tryOutNotification()
{
_trayIcon.ShowBalloonTip((int)TimeSpan.FromSeconds(5).TotalMilliseconds, "Test Notification", "If you didn't see this, you'd probabaly have issue with handling authentication actions", ToolTipIcon.Info);
}

#endregion
}
}
14 changes: 6 additions & 8 deletions SoftU2FDaemon/Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project>
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>x64</Platform>
<TargetFramework>net5.0-windows</TargetFramework>
<PublishDir>bin\Release\net5.0\publish\</PublishDir>
<Platform>Any CPU</Platform>
<TargetFramework>net6.0-windows</TargetFramework>
<PublishDir>bin\Release\net6.0\publish\</PublishDir>
<SelfContained>true</SelfContained>
<_IsPortable>true</_IsPortable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishTrimmed>True</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
</Project>
31 changes: 29 additions & 2 deletions SoftU2FDaemon/SoftU2FDaemon.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Resources\tray.ico</ApplicationIcon>
<StartupObject>SoftU2FDaemon.App</StartupObject>
Expand Down Expand Up @@ -35,6 +35,33 @@
<Resources Include="$(ProjectDir)Resources\*.*" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>

<Target Name="CopyFiles" AfterTargets="Build">
<Copy SourceFiles="..\U2FLib\NativeBridge.dll" DestinationFolder="$(OutDir)" />
<Copy SourceFiles="@(Resources)" DestinationFolder="$(OutDir)" />
Expand Down
Loading

0 comments on commit 3ae8af8

Please sign in to comment.