Skip to content

Commit

Permalink
Implement the deletion of security keys
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoessler committed Aug 18, 2024
1 parent 7262a9f commit ecc169b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 12 deletions.
10 changes: 10 additions & 0 deletions Guard.Core/Security/Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ internal static async Task AddWebAuthnDevice(WebauthnDevice device, AssertionRes
await SaveFile();
}

public static async Task RemoveWebAuthnDevice(WebauthnDevice device)
{
ArgumentNullException.ThrowIfNull(authData);

authData.WebAuthn ??= [];

authData.WebAuthn.Remove(device);
await SaveFile();
}

public static async Task LoginWithWebAuthn(IntPtr windowHandle)
{
if (authData == null || authData.LoginSalt == null)
Expand Down
2 changes: 1 addition & 1 deletion Guard.Core/Security/WebAuthn/WebAuthnInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static int GetApiVersion()
);
}
_apiVersion = WebAuthNGetApiVersionNumber();
Log.Logger.Debug("WebAuthn API version: {ApiVersion}", _apiVersion);
Log.Logger.Information("WebAuthn API version: {ApiVersion}", _apiVersion);
}
return _apiVersion
?? throw new PlatformNotSupportedException("Can not get WebAuthn API version.");
Expand Down
5 changes: 5 additions & 0 deletions Guard.WPF/Resources/Strings.de.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
<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>

<!-- WebAuthn -->
<system:String x:Key="i.page.webauthnpage">Sicherheitsschlüssel (FIDO2)</system:String>
<system:String x:Key="i.webauthn.add.title">Sicherheitsschlüssel hinzufügen</system:String>
<system:String x:Key="i.webauthn.add.description">Registriere einen neuen Schlüssel</system:String>
Expand All @@ -87,6 +89,9 @@
<system:String x:Key="i.webauthn.dialog1.input">Name zur Identifikation des Schlüssels</system:String>
<system:String x:Key="i.webauthn.dialog1.namerequired">Es muss ein Name für den Sicherheitsschlüssel eingegeben werden</system:String>
<system:String x:Key="i.webauthn.dialog.nameexists">Es existiert bereits ein Sicherheitsschlüssel mit diesem Namen</system:String>
<system:String x:Key="i.webauthn.delete.title">Sicherheitsschlüssel entfernen</system:String>
<system:String x:Key="i.webauthn.delete.content">Bist du sicher, dass du den Sicherheitsschlüssel @Name entfernen möchten? Du kannst diesen Schlüssel nicht mehr für die Authentifizierung verwenden.</system:String>
<system:String x:Key="i.webauthn.delete.yes">Entfernen</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
5 changes: 5 additions & 0 deletions Guard.WPF/Resources/Strings.en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<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>

<!-- WebAuthn -->
<system:String x:Key="i.page.webauthnpage">Security Key (FIDO2)</system:String>
<system:String x:Key="i.webauthn.add.title">Add Security Key</system:String>
<system:String x:Key="i.webauthn.add.description">Register a new key</system:String>
Expand All @@ -86,6 +88,9 @@
<system:String x:Key="i.webauthn.dialog1.content2">Please note that after the system pop-up says that you can now log in with the security key, you have to complete the directly following authentication step to finish the registration.</system:String>
<system:String x:Key="i.webauthn.dialog1.namerequired">You have to enter a name for the security key</system:String>
<system:String x:Key="i.webauthn.dialog.nameexists">A security key with this name already exists</system:String>
<system:String x:Key="i.webauthn.delete.title">Remove Security Key</system:String>
<system:String x:Key="i.webauthn.delete.content">Are you sure you want to remove the security key @Name? You can not use this key for authentication anymore.</system:String>
<system:String x:Key="i.webauthn.delete.yes">Remove</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
5 changes: 5 additions & 0 deletions Guard.WPF/Resources/Strings.fr.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<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>

<!-- WebAuthn -->
<system:String x:Key="i.page.webauthnpage">Clé de sécurité (FIDO2)</system:String>
<system:String x:Key="i.webauthn.add.title">Ajouter une clé de sécurité</system:String>
<system:String x:Key="i.webauthn.add.description">Enregistrer une nouvelle clé</system:String>
Expand All @@ -86,6 +88,9 @@
<system:String x:Key="i.webauthn.dialog1.content2">Veuillez noter qu'après l'apparition de la fenêtre contextuelle du système indiquant que vous pouvez désormais vous connecter avec la clé de sécurité, vous devez terminer l'étape d'authentification qui suit immédiatement pour finaliser l'inscription.</system:String>
<system:String x:Key="i.webauthn.dialog.nameexists">Il existe déjà une clé de sécurité avec ce nom</system:String>
<system:String x:Key="i.webauthn.dialog1.namerequired">Vous devez entrer un nom pour la clé de sécurité</system:String>
<system:String x:Key="i.webauthn.delete.title">Supprimer la clé de sécurité</system:String>
<system:String x:Key="i.webauthn.delete.content">Êtes-vous sûr de vouloir supprimer la clé de sécurité @Name ? Vous ne pourrez plus utiliser cette clé pour l'authentification.</system:String>
<system:String x:Key="i.webauthn.delete.yes">Supprimer</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
5 changes: 5 additions & 0 deletions Guard.WPF/Resources/Strings.zh_cn.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<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>

<!-- WebAuthn -->
<system:String x:Key="i.page.webauthnpage">安全密鑰 (FIDO2)</system:String>
<system:String x:Key="i.webauthn.add.title">添加安全密鑰</system:String>
<system:String x:Key="i.webauthn.add.description">註冊新密鑰</system:String>
Expand All @@ -86,6 +88,9 @@
<system:String x:Key="i.webauthn.dialog1.content2">請注意,系統彈出提示您可以使用安全密鑰登錄後,您必須完成隨後的驗證步驟以完成註冊。</system:String>
<system:String x:Key="i.webauthn.dialog.nameexists">已經存在具有此名稱的安全密鑰</system:String>
<system:String x:Key="i.webauthn.dialog1.namerequired">您必須輸入安全金鑰的名稱</system:String>
<system:String x:Key="i.webauthn.delete.title">移除安全密鑰</system:String>
<system:String x:Key="i.webauthn.delete.content">您確定要移除安全密鑰 @Name 嗎?您將無法再使用此密鑰進行身份驗證。</system:String>
<system:String x:Key="i.webauthn.delete.yes">移除</system:String>

<!-- 应用设置 -->
<system:String x:Key="i.welcome.subtext">感谢下载!请选择您想要如何保护您的令牌。</system:String>
Expand Down
5 changes: 5 additions & 0 deletions Guard.WPF/Resources/Strings.zh_tw.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<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>

<!-- WebAuthn -->
<system:String x:Key="i.page.webauthnpage">安全密钥 (FIDO2)</system:String>
<system:String x:Key="i.webauthn.add.title">添加安全密钥</system:String>
<system:String x:Key="i.webauthn.add.description">注册新密钥</system:String>
Expand All @@ -86,6 +88,9 @@
<system:String x:Key="i.webauthn.dialog1.content2">请注意,系统弹出提示您可以使用安全密钥登录后,您必须完成随后验证步骤以完成注册。</system:String>
<system:String x:Key="i.webauthn.dialog.nameexists">已经存在具有此名称的安全密钥</system:String>
<system:String x:Key="i.webauthn.dialog1.namerequired">您必须输入安全密钥的名称</system:String>
<system:String x:Key="i.webauthn.delete.title">移除安全密钥</system:String>
<system:String x:Key="i.webauthn.delete.content">您确定要移除安全密钥 @Name 吗?您将无法再使用此密钥进行身份验证。</system:String>
<system:String x:Key="i.webauthn.delete.yes">移除</system:String>

<!-- 應用設定 -->
<system:String x:Key="i.welcome.subtext">感謝下載!請選擇您想要如何保護您的令牌。</system:String>
Expand Down
50 changes: 39 additions & 11 deletions Guard.WPF/Views/Pages/Preferences/WebAuthnPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Windows;
using System.Windows.Controls;
using Guard.Core;
using Guard.Core.Models;
using Guard.Core.Security;
using Guard.Core.Security.WebAuthn;
Expand Down Expand Up @@ -99,6 +100,7 @@ private async void Add_Click(object sender, RoutedEventArgs e)
}
catch (Exception ex)
{
Log.Logger.Error("Unhandled WebAuthn exception on key creation: {0}", ex.Message);
if (ex.Message == "Cancelled")
{
return;
Expand All @@ -119,16 +121,41 @@ private void LoadKeys()
KeysContainer.Children.Clear();
foreach (var key in keys)
{
var delBtn = new Wpf.Ui.Controls.Button()
{
Margin = new Thickness(0, 0, 8, 0),
Icon = new SymbolIcon() { Symbol = SymbolRegular.Delete24 },
};
delBtn.Click += async (sender, e) =>
{
var deleteMessageBox = new Wpf.Ui.Controls.MessageBox
{
Title = I18n.GetString("webauthn.delete.title"),
Content = I18n.GetString("webauthn.delete.content")
.Replace(
"@Name",
!string.IsNullOrEmpty(key.EncryptedName)
? encryptionHelper.DecryptString(key.EncryptedName)
: "???"
),
IsPrimaryButtonEnabled = true,
PrimaryButtonText = I18n.GetString("webauthn.delete.yes"),
CloseButtonText = I18n.GetString("dialog.close"),
MaxWidth = 400
};

var result = await deleteMessageBox.ShowDialogAsync();
if (result == Wpf.Ui.Controls.MessageBoxResult.Primary)
{
DeleteKey(key);
}
};
KeysContainer.Children.Add(
new CardControl()
{
Width = 320,
Margin = new Thickness(0, 15, 15, 0),
Icon = new SymbolIcon()
{
//FontSize = 32,
Symbol = SymbolRegular.UsbStick24
},
Icon = new SymbolIcon() { Symbol = SymbolRegular.UsbStick24 },
Header = new Grid()
{
Margin = new Thickness(0, 0, 35, 0),
Expand All @@ -145,15 +172,16 @@ private void LoadKeys()
},
}
},
Content = new Wpf.Ui.Controls.Button()
{
Margin = new Thickness(0, 0, 8, 0),

Icon = new SymbolIcon() { Symbol = SymbolRegular.Delete24 },
},
Content = delBtn
}
);
}
}

private async void DeleteKey(WebauthnDevice key)
{
await Auth.RemoveWebAuthnDevice(key);
LoadKeys();
}
}
}

0 comments on commit ecc169b

Please sign in to comment.