From acc29c8871f387c088f4016dcf55cb40850c3ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6ssler?= Date: Tue, 23 Apr 2024 18:53:15 +0200 Subject: [PATCH] Delete all custom icons on reset --- Guard/Core/Icons/IconManager.cs | 8 ++++++ .../Importer/AegisAuthenticatorImporter.cs | 25 ++++++++++--------- Guard/Core/Storage/Reset.cs | 2 ++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Guard/Core/Icons/IconManager.cs b/Guard/Core/Icons/IconManager.cs index a47b1c1..b0bc69a 100644 --- a/Guard/Core/Icons/IconManager.cs +++ b/Guard/Core/Icons/IconManager.cs @@ -125,5 +125,13 @@ public static void RemoveCustomIcon(string name) File.Delete(path); } } + + public static void RemoveAllCustomIcons() + { + if (Directory.Exists(customIconsPath)) + { + Directory.Delete(customIconsPath, true); + } + } } } diff --git a/Guard/Core/Import/Importer/AegisAuthenticatorImporter.cs b/Guard/Core/Import/Importer/AegisAuthenticatorImporter.cs index a1581e7..de58de6 100644 --- a/Guard/Core/Import/Importer/AegisAuthenticatorImporter.cs +++ b/Guard/Core/Import/Importer/AegisAuthenticatorImporter.cs @@ -14,7 +14,7 @@ internal class AegisAuthenticatorImporter : IImporter public IImporter.ImportType Type => IImporter.ImportType.File; public string SupportedFileExtensions => "Aegis Authenticator Export (*.json) | *.json"; - private bool isEncryptedBackup(string jsonString) + private static bool IsEncryptedBackup(string jsonString) { JsonDocument doc = JsonDocument.Parse(jsonString); JsonElement root = doc.RootElement; @@ -40,7 +40,7 @@ public bool RequiresPassword(string? path) { ArgumentNullException.ThrowIfNull(path); string jsonString = File.ReadAllText(path, Encoding.UTF8); - return isEncryptedBackup(jsonString); + return IsEncryptedBackup(jsonString); } // https://nsec.rocks/docs/api/nsec.cryptography.passwordbasedkeyderivationalgorithm @@ -50,9 +50,9 @@ public bool RequiresPassword(string? path) ArgumentNullException.ThrowIfNull(path); string jsonString = File.ReadAllText(path, Encoding.UTF8); - AegisExport.Database? database = null; + AegisExport.Database? database; - if (isEncryptedBackup(jsonString)) + if (IsEncryptedBackup(jsonString)) { // Encrypted backup ArgumentNullException.ThrowIfNull(password); @@ -116,14 +116,15 @@ public bool RequiresPassword(string? path) ); } - Scrypt scrypt = new Scrypt( - new ScryptParameters() - { - Cost = slot.N.Value, - BlockSize = slot.R.Value, - Parallelization = slot.P.Value, - } - ); + Scrypt scrypt = + new( + new ScryptParameters() + { + Cost = slot.N.Value, + BlockSize = slot.R.Value, + Parallelization = slot.P.Value, + } + ); try { diff --git a/Guard/Core/Storage/Reset.cs b/Guard/Core/Storage/Reset.cs index 32054e8..98dda2c 100644 --- a/Guard/Core/Storage/Reset.cs +++ b/Guard/Core/Storage/Reset.cs @@ -1,4 +1,5 @@ using System.IO; +using Guard.Core.Icons; using Guard.Core.Installation; using Guard.Core.Security; @@ -12,6 +13,7 @@ internal static void DeleteEverything() Database.Deinit(); _ = WindowsHello.Unregister(); Auth.DeleteWindowsHelloProtectedKey(); + IconManager.RemoveAllCustomIcons(); string[] files = ["auth-keys", "settings", "TokenDatabase.db", "TokenDatabase-log.db"];