Skip to content

Commit

Permalink
Improve logging and error msg for importer
Browse files Browse the repository at this point in the history
  • Loading branch information
timokoessler committed Oct 19, 2024
1 parent 43d517d commit e9cb2f0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion Guard.WPF/Core/Import/Importer/AegisAuthenticatorImporter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO;
using System.Text;
using System.Text.Json;
using Guard.Core;
using Guard.Core.Models;
using Guard.Core.Security;
using Guard.WPF.Core.Icons;
Expand Down Expand Up @@ -78,6 +79,13 @@ public bool RequiresPassword(string? path)
);
}

if (!Aes256Gcm.IsSupported)
{
throw new Exception(
"AES256-GCM is not supported on this platform. The reason may be that your CPU does not support hardware-accelerated AES256-GCM encryption."
);
}

byte[]? masterKey = null;

foreach (AegisExport.HeaderSlot slot in export.Header.Slots)
Expand Down Expand Up @@ -170,14 +178,18 @@ public bool RequiresPassword(string? path)
);
break;
}
catch (Exception)
catch (Exception e)
{
Log.Logger.Error(
$"Failed to decrypt Aegis master key: {e.Message}\n{e.StackTrace}"
);
continue;
}
}

if (masterKey == null)
{
Log.Logger.Error("Failed to decrypt Aegis master key: master key is null");
throw new Exception(I18n.GetString("import.password.invalid"));
}

Expand Down
2 changes: 1 addition & 1 deletion Guard.WPF/Core/Import/Importer/AuthenticatorProImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private static BackupType GetBackupType(byte[] data)
if (!Aes256Gcm.IsSupported)
{
throw new Exception(
"This platform does not support hardware-accelerated AES (GCM) encryption that is required to import this file."
"AES256-GCM is not supported on this platform. The reason may be that your CPU does not support hardware-accelerated AES256-GCM encryption."
);
}

Expand Down
2 changes: 1 addition & 1 deletion Guard.WPF/Core/Import/Importer/TwoFasImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public bool RequiresPassword(string? path)
if (!Aes256Gcm.IsSupported)
{
throw new Exception(
"This platform does not support hardware-accelerated AES (GCM) encryption that is required to import this file."
"AES256-GCM is not supported on this platform. The reason may be that your CPU does not support hardware-accelerated AES256-GCM encryption."
);
}

Expand Down

0 comments on commit e9cb2f0

Please sign in to comment.