Skip to content

Commit

Permalink
Delete all custom icons on reset
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoessler committed Apr 23, 2024
1 parent 97242b0 commit acc29c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
8 changes: 8 additions & 0 deletions Guard/Core/Icons/IconManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
25 changes: 13 additions & 12 deletions Guard/Core/Import/Importer/AegisAuthenticatorImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions Guard/Core/Storage/Reset.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using Guard.Core.Icons;
using Guard.Core.Installation;
using Guard.Core.Security;

Expand All @@ -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"];

Expand Down

0 comments on commit acc29c8

Please sign in to comment.