Skip to content

Commit

Permalink
Add webauthn to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoessler committed Aug 4, 2024
1 parent ed74125 commit cbc282f
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Guard.Core/Security/WindowsHello.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private static string GetAccountName()

public static async Task<KeyCredentialRetrievalResult> Register()
{
_ = FocusSecurityPrompt();
FocusSecurityPrompt();
return await KeyCredentialManager.RequestCreateAsync(
GetAccountName(),
KeyCredentialCreationOption.FailIfExists
Expand All @@ -27,7 +27,7 @@ public static async Task<bool> IsAvailable()

/*public static async Task<bool> RequestSimpleVerification()
{
_ = FocusSecurityPrompt();
FocusSecurityPrompt();
UserConsentVerificationResult consentResult =
await UserConsentVerifier.RequestVerificationAsync(
I18n.GetString("win.hello.request")
Expand All @@ -43,7 +43,7 @@ await UserConsentVerifier.RequestVerificationAsync(
/// <returns>A string used as key with argon2id</returns>
public static async Task<string> GetSignedChallenge()
{
_ = FocusSecurityPrompt();
FocusSecurityPrompt();
var openKeyResult = await KeyCredentialManager.OpenAsync(GetAccountName());
if (openKeyResult.Status != KeyCredentialStatus.Success)
{
Expand Down Expand Up @@ -74,7 +74,7 @@ public static async Task Unregister()
await KeyCredentialManager.DeleteAsync(GetAccountName());
}

public static async Task FocusSecurityPrompt()
public static async void FocusSecurityPrompt()
{
const string className = "Credential Dialog Xaml Host";
const int maxTries = 3;
Expand Down
4 changes: 4 additions & 0 deletions Guard.WPF/Resources/Strings.de.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<system:String x:Key="i.settings.locktime.thirtyminutes">30 Minuten</system:String>
<system:String x:Key="i.settings.locktime.onehour">1 Stunde</system:String>
<system:String x:Key="i.page.changepasswordpage">Passwort ändern</system:String>
<system:String x:Key="i.settings.webauthn">Sicherheitsschlüssel (FIDO2)</system:String>
<system:String x:Key="i.settings.webauthn.description">Melde dich mit einem Sicherheitsschlüssel an</system:String>
<system:String x:Key="i.settings.webauthn.button">Konfigurieren</system:String>
<system:String x:Key="i.settings.webauthn.notsupported">Dein Betriebssystem scheint WebAuthn nicht zu unterstützen.</system:String>

<!-- Application setup -->
<system:String x:Key="i.welcome.subtext">Vielen Dank fürs Herunterladen! Bitte wähle, wie du deine Token sichern möchtest.</system:String>
Expand Down
4 changes: 4 additions & 0 deletions Guard.WPF/Resources/Strings.en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
<system:String x:Key="i.settings.locktime.thirtyminutes">30 minutes</system:String>
<system:String x:Key="i.settings.locktime.onehour">1 hour</system:String>
<system:String x:Key="i.page.changepasswordpage">Change password</system:String>
<system:String x:Key="i.settings.webauthn">Security key (FIDO2)</system:String>
<system:String x:Key="i.settings.webauthn.description">Login with a hardware security key</system:String>
<system:String x:Key="i.settings.webauthn.button">Configure</system:String>
<system:String x:Key="i.settings.webauthn.notsupported">Your operating system does not seem to support WebAuthn.</system:String>

<!-- Application setup -->
<system:String x:Key="i.welcome.subtext">Thanks for downloading! Please choose how you would like to secure your tokens.</system:String>
Expand Down
4 changes: 4 additions & 0 deletions Guard.WPF/Resources/Strings.fr.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
<system:String x:Key="i.settings.locktime.thirtyminutes">30 minutes</system:String>
<system:String x:Key="i.settings.locktime.onehour">1 heure</system:String>
<system:String x:Key="i.page.changepasswordpage">Changer le mot de passe</system:String>
<system:String x:Key="i.settings.webauthn">Clé de sécurité (FIDO2)</system:String>
<system:String x:Key="i.settings.webauthn.description">Se connecter avec une clé de sécurité matérielle</system:String>
<system:String x:Key="i.settings.webauthn.button">Configurer</system:String>
<system:String x:Key="i.settings.webauthn.notsupported">Votre système d'exploitation ne semble pas prendre en charge WebAuthn.</system:String>

<!-- Application setup -->
<system:String x:Key="i.welcome.subtext">Merci pour le téléchargement ! Veuillez choisir comment vous souhaitez sécuriser vos jetons.</system:String>
Expand Down
4 changes: 4 additions & 0 deletions Guard.WPF/Resources/Strings.zh_cn.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
<system:String x:Key="i.settings.locktime.thirtyminutes">30分钟</system:String>
<system:String x:Key="i.settings.locktime.onehour">1小时</system:String>
<system:String x:Key="i.page.changepasswordpage">更改密码</system:String>
<system:String x:Key="i.settings.webauthn">安全密鑰 (FIDO2)</system:String>
<system:String x:Key="i.settings.webauthn.description">使用硬件安全密鑰登錄</system:String>
<system:String x:Key="i.settings.webauthn.button">配置</system:String>
<system:String x:Key="i.settings.webauthn.notsupported">您的操作系統似乎不支持WebAuthn。</system:String>

<!-- 应用设置 -->
<system:String x:Key="i.welcome.subtext">感谢下载!请选择您想要如何保护您的令牌。</system:String>
Expand Down
4 changes: 4 additions & 0 deletions Guard.WPF/Resources/Strings.zh_tw.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
<system:String x:Key="i.settings.locktime.thirtyminutes">30分鐘</system:String>
<system:String x:Key="i.settings.locktime.onehour">1小時</system:String>
<system:String x:Key="i.page.changepasswordpage">更改密碼</system:String>
<system:String x:Key="i.settings.webauthn">安全密钥 (FIDO2)</system:String>
<system:String x:Key="i.settings.webauthn.description">使用硬件安全密钥登录</system:String>
<system:String x:Key="i.settings.webauthn.button">配置</system:String>
<system:String x:Key="i.settings.webauthn.notsupported">您的操作系统似乎不支持WebAuthn。</system:String>

<!-- 應用設定 -->
<system:String x:Key="i.welcome.subtext">感謝下載!請選擇您想要如何保護您的令牌。</system:String>
Expand Down
34 changes: 33 additions & 1 deletion Guard.WPF/Views/Pages/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
<ui:ToggleSwitch x:Name="ScreenLockSwitch" Grid.Column="1" />
</ui:CardControl>
</Grid>
<Grid Margin="0,0,0,10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
Expand Down Expand Up @@ -272,6 +272,38 @@
<ui:CardControl
Grid.Column="1"
Margin="15,0,0,15"
Icon="{ui:SymbolIcon UsbStick24}">
<ui:CardControl.Header>
<Grid Margin="0,0,35,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ui:TextBlock
Grid.Row="0"
FontTypography="Body"
Text="{DynamicResource i.settings.webauthn}" />
<ui:TextBlock
Grid.Row="1"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="{DynamicResource i.settings.webauthn.description}" />
</Grid>
</ui:CardControl.Header>
<ui:Button
Grid.Column="1"
Click="WebAuthn_Button_Click"
Content="{DynamicResource i.settings.webauthn.button}"
Icon="{ui:SymbolIcon Settings24}" />
</ui:CardControl>
</Grid>
<Grid Margin="0,0,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:CardControl
Grid.Column="0"
Margin="0,0,0,15"
Icon="{ui:SymbolIcon Delete24}">
<ui:CardControl.Header>
<Grid Margin="0,0,35,0">
Expand Down
27 changes: 26 additions & 1 deletion Guard.WPF/Views/Pages/Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
using Guard.Core;
using Guard.Core.Models;
using Guard.Core.Security;
using Guard.Core.Security.WebAuthn;
using Guard.Core.Storage;
using Guard.WPF.Core;
using Guard.WPF.Core.Installation;
using Guard.WPF.Core.Security;
using Guard.WPF.Views.Controls;
using Serilog.Core;
using Wpf.Ui.Controls;

namespace Guard.WPF.Views.Pages
Expand Down Expand Up @@ -476,12 +478,35 @@ private async void Reset_Button_Click(object sender, RoutedEventArgs e)
Log.Logger.Error("Error resetting app: {0} {1}", ex.Message, ex.StackTrace);
_ = await new Wpf.Ui.Controls.MessageBox
{
Title = "Error",
Title = I18n.GetString("error"),
Content = ex.Message,
CloseButtonText = I18n.GetString("dialog.close"),
MaxWidth = 500
}.ShowDialogAsync();
}
}

private async void WebAuthn_Button_Click(object sender, RoutedEventArgs e)
{
if (!WebAuthnHelper.IsSupported())
{
_ = new Wpf.Ui.Controls.MessageBox
{
Title = I18n.GetString("error"),
Content = I18n.GetString("settings.webauthn.notsupported"),
CloseButtonText = I18n.GetString("dialog.close"),
MaxWidth = 400
}.ShowDialogAsync();
return;
}

Log.Logger.Information(
"Starting WebAuthn registration with webauthn.dll version {0}",
WebAuthnHelper.GetApiVersion()
);

//var result = await WebAuthnHelper.Register(mainWindow.GetWindowHandle());
//var result = await WebAuthnHelper.Assert(mainWindow.GetWindowHandle());
}
}
}

0 comments on commit cbc282f

Please sign in to comment.