aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-05-15 22:01:16 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-05-15 22:01:16 -0400
commit21c6c85f540740ac29536a7091346a731aa85148 (patch)
tree88f79dc83041ea1fa3ecd71573dd2b864f4ffeca
parent8e77289041349b16536497f48f0c0a4ec6fe30f5 (diff)
fix: #3 Error raised when managed password type disposed
-rw-r--r--lib/VNLib.Plugins.Extensions.Loading/src/ManagedPasswordHashing.cs29
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/ManagedPasswordHashing.cs b/lib/VNLib.Plugins.Extensions.Loading/src/ManagedPasswordHashing.cs
index 28b3a08..3718ea5 100644
--- a/lib/VNLib.Plugins.Extensions.Loading/src/ManagedPasswordHashing.cs
+++ b/lib/VNLib.Plugins.Extensions.Loading/src/ManagedPasswordHashing.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Extensions.Loading
@@ -25,11 +25,13 @@
using System;
using System.Linq;
using System.Text.Json;
+using System.Threading.Tasks;
using System.Collections.Generic;
using VNLib.Hashing;
using VNLib.Utils;
using VNLib.Utils.Memory;
+using VNLib.Utils.Logging;
using VNLib.Utils.Extensions;
using VNLib.Plugins.Essentials.Accounts;
@@ -123,7 +125,11 @@ namespace VNLib.Plugins.Extensions.Loading
if(config.TryGetValue("lib_path", out JsonElement manualLibPath))
{
- SafeArgon2Library lib = VnArgon2.LoadCustomLibrary(manualLibPath.GetString()!, System.Runtime.InteropServices.DllImportSearchPath.SafeDirectories);
+ SafeArgon2Library lib = VnArgon2.LoadCustomLibrary(
+ manualLibPath.GetString()!,
+ System.Runtime.InteropServices.DllImportSearchPath.SafeDirectories
+ );
+
_ = plugin.RegisterForUnload(lib.Dispose);
safeLib = lib;
}
@@ -154,6 +160,15 @@ namespace VNLib.Plugins.Extensions.Loading
//Get the pepper from secret storage
_pepper = plugin.GetSecretAsync(LoadingExtensions.PASSWORD_HASHING_KEY)
.ToLazy(static sr => sr.GetFromBase64());
+
+ _ = _pepper.AsTask()
+ .ContinueWith(secT => {
+ plugin.Log.Error("Failed to load password pepper: {reason}", secT.Exception?.Message);
+ },
+ default,
+ TaskContinuationOptions.OnlyOnFaulted, //Only run if an exception occured to notify the user during startup
+ TaskScheduler.Default
+ );
}
public SecretProvider(PluginBase plugin)
@@ -163,7 +178,8 @@ namespace VNLib.Plugins.Extensions.Loading
//Get the pepper from secret storage
_pepper = plugin.GetSecretAsync(LoadingExtensions.PASSWORD_HASHING_KEY)
- .ToLazy(static sr => sr.GetFromBase64());
+ .ToBase64Bytes()
+ .AsLazy();
}
///<inheritdoc/>
@@ -193,9 +209,10 @@ namespace VNLib.Plugins.Extensions.Loading
protected override void Free()
{
- if (_pepper.Completed)
- {
- //Clear the pepper if set
+ Task pepperTask = _pepper.AsTask();
+ //Only zero pepper value if the pepper was retrieved successfully
+ if (pepperTask.IsCompletedSuccessfully)
+ {
MemoryUtil.InitializeBlock(_pepper.Value.AsSpan());
}
}