aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar vman <public@vaughnnugent.com>2022-12-28 14:16:22 -0500
committerLibravatar vman <public@vaughnnugent.com>2022-12-28 14:16:22 -0500
commitb6481038bc6573af30492e9ce52b36d9f64195f3 (patch)
tree375c52f2929dbf83a5d0d1be3642ba34629f2b2a
parenta5ad943584e91bfbd953dc373a7a313367c7e0ae (diff)
Secret loading extensions
-rw-r--r--VNLib.Plugins.Essentials.Accounts.Admin/VNLib.Plugins.Essentials.Accounts.Admin.csproj2
-rw-r--r--VNLib.Plugins.Essentials.Accounts.Registration/src/AccountValidations.cs2
-rw-r--r--VNLib.Plugins.Essentials.Accounts.Registration/src/Endpoints/RegistrationEntpoint.cs2
-rw-r--r--VNLib.Plugins.Essentials.Accounts.Registration/src/VNLib.Plugins.Essentials.Accounts.Registration.csproj2
-rw-r--r--VNLib.Plugins.Essentials.Accounts/MFA/UserMFAExtensions.cs48
-rw-r--r--VNLib.Plugins.Essentials.Accounts/VNLib.Plugins.Essentials.Accounts.csproj2
-rw-r--r--VNLib.Plugins.Essentials.Content.Routing/Router.cs4
-rw-r--r--VNLib.Plugins.Essentials.Content.Routing/VNLib.Plugins.Essentials.Content.Routing.csproj2
-rw-r--r--VNLib.Plugins.Essentials.SocialOauth/VNLib.Plugins.Essentials.SocialOauth.csproj4
9 files changed, 33 insertions, 35 deletions
diff --git a/VNLib.Plugins.Essentials.Accounts.Admin/VNLib.Plugins.Essentials.Accounts.Admin.csproj b/VNLib.Plugins.Essentials.Accounts.Admin/VNLib.Plugins.Essentials.Accounts.Admin.csproj
index 53cc189..2bb4a38 100644
--- a/VNLib.Plugins.Essentials.Accounts.Admin/VNLib.Plugins.Essentials.Accounts.Admin.csproj
+++ b/VNLib.Plugins.Essentials.Accounts.Admin/VNLib.Plugins.Essentials.Accounts.Admin.csproj
@@ -5,6 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AnalysisLevel>latest-all</AnalysisLevel>
+ <SignAssembly>True</SignAssembly>
+ <AssemblyOriginatorKeyFile>\\vaughnnugent.com\Internal\Folder Redirection\vman\Documents\Programming\Software\StrongNameingKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
diff --git a/VNLib.Plugins.Essentials.Accounts.Registration/src/AccountValidations.cs b/VNLib.Plugins.Essentials.Accounts.Registration/src/AccountValidations.cs
index df47130..b84728b 100644
--- a/VNLib.Plugins.Essentials.Accounts.Registration/src/AccountValidations.cs
+++ b/VNLib.Plugins.Essentials.Accounts.Registration/src/AccountValidations.cs
@@ -113,7 +113,7 @@ namespace VNLib.Plugins.Essentials.Accounts.Registration
reqVal.RuleFor(static s => s.ClientId)
.NotEmpty()
- .IllegalCharacters()
+ .AlphaNumericOnly()
.Length(1, 100);
//Convert to universal time before validating
diff --git a/VNLib.Plugins.Essentials.Accounts.Registration/src/Endpoints/RegistrationEntpoint.cs b/VNLib.Plugins.Essentials.Accounts.Registration/src/Endpoints/RegistrationEntpoint.cs
index b56cb3c..74f2aa1 100644
--- a/VNLib.Plugins.Essentials.Accounts.Registration/src/Endpoints/RegistrationEntpoint.cs
+++ b/VNLib.Plugins.Essentials.Accounts.Registration/src/Endpoints/RegistrationEntpoint.cs
@@ -106,7 +106,7 @@ namespace VNLib.Plugins.Essentials.Accounts.Registration.Endpoints
}, TaskScheduler.Default);
//Register timeout for cleanup
- _ = plugin.ScheduleInterval(this, TimeSpan.FromSeconds(60));
+ plugin.ScheduleInterval(this, TimeSpan.FromSeconds(60));
}
private static IValidator<string> GetJwtValidator()
diff --git a/VNLib.Plugins.Essentials.Accounts.Registration/src/VNLib.Plugins.Essentials.Accounts.Registration.csproj b/VNLib.Plugins.Essentials.Accounts.Registration/src/VNLib.Plugins.Essentials.Accounts.Registration.csproj
index 5a8597f..8b2264e 100644
--- a/VNLib.Plugins.Essentials.Accounts.Registration/src/VNLib.Plugins.Essentials.Accounts.Registration.csproj
+++ b/VNLib.Plugins.Essentials.Accounts.Registration/src/VNLib.Plugins.Essentials.Accounts.Registration.csproj
@@ -14,6 +14,8 @@
<AssemblyVersion>1.0.0.1</AssemblyVersion>
<AssemblyName>Essentials.EmailRegistration</AssemblyName>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
+ <SignAssembly>True</SignAssembly>
+ <AssemblyOriginatorKeyFile>\\vaughnnugent.com\Internal\Folder Redirection\vman\Documents\Programming\Software\StrongNameingKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<!-- Resolve nuget dll files and store them in the output dir -->
diff --git a/VNLib.Plugins.Essentials.Accounts/MFA/UserMFAExtensions.cs b/VNLib.Plugins.Essentials.Accounts/MFA/UserMFAExtensions.cs
index 4fa76ef..1ec9953 100644
--- a/VNLib.Plugins.Essentials.Accounts/MFA/UserMFAExtensions.cs
+++ b/VNLib.Plugins.Essentials.Accounts/MFA/UserMFAExtensions.cs
@@ -29,7 +29,6 @@ using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text.Json.Serialization;
using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
using VNLib.Hashing;
using VNLib.Utils;
@@ -138,7 +137,7 @@ namespace VNLib.Plugins.Essentials.Accounts.MFA
//calculate the time step
long timeStep = (long)Math.Floor(window.ToUnixTimeSeconds() / config.TOTPPeriod.TotalSeconds);
//try to compute the hash
- _ = BitConverter.TryWriteBytes(stepBuffer, timeStep) ? 0 : throw new Exception("Failed to format TOTP time step");
+ _ = BitConverter.TryWriteBytes(stepBuffer, timeStep) ? 0 : throw new InternalBufferTooSmallException("Failed to format TOTP time step");
//If platform is little endian, reverse the byte order
if (BitConverter.IsLittleEndian)
{
@@ -188,8 +187,6 @@ namespace VNLib.Plugins.Essentials.Accounts.MFA
const string MFA_CONFIG_KEY = "mfa";
- private static readonly ConditionalWeakTable<PluginBase, Lazy<MFAConfig?>> _lazyMfaConfigs = new();
-
/// <summary>
/// Gets the plugins ambient <see cref="PasswordHashing"/> if loaded, or loads it if required. This class will
/// be unloaded when the plugin us unloaded.
@@ -201,38 +198,31 @@ namespace VNLib.Plugins.Essentials.Accounts.MFA
/// <exception cref="ObjectDisposedException"></exception>
public static MFAConfig? GetMfaConfig(this PluginBase plugin)
{
- static Lazy<MFAConfig?> LoadMfaConfig(PluginBase pbase)
+ static MFAConfig? LoadMfaConfig(PluginBase pbase)
{
- //Lazy load func
- MFAConfig? Load()
+ //Try to get the configuration object
+ IReadOnlyDictionary<string, JsonElement>? conf = pbase.TryGetConfig(MFA_CONFIG_KEY);
+
+ if (conf == null)
{
- //Try to get the configuration object
- IReadOnlyDictionary<string, JsonElement>? conf = pbase.TryGetConfig(MFA_CONFIG_KEY);
-
- if (conf == null)
- {
- return null;
- }
- //Init mfa config
- MFAConfig mfa = new(conf);
-
- //Recover secret from config and dangerous 'lazy load'
- _ = pbase.DeferTask(async () =>
- {
- using SecretResult? secret = await pbase.TryGetSecretAsync("mfa_secret");
- mfa.MFASecret = secret != null ? secret.GetJsonWebKey() : null;
-
- },50);
-
- return mfa;
+ return null;
}
- //Return new lazy for
- return new(Load);
+ //Init mfa config
+ MFAConfig mfa = new(conf);
+
+ //Recover secret from config and dangerous 'lazy load'
+ _ = pbase.DeferTask(async () =>
+ {
+ mfa.MFASecret = await pbase.TryGetSecretAsync("mfa_secret").ToJsonWebKey();
+
+ }, 50);
+
+ return mfa;
}
plugin.ThrowIfUnloaded();
//Get/load the passwords one time only
- return _lazyMfaConfigs.GetValue(plugin, LoadMfaConfig).Value;
+ return LoadingExtensions.GetOrCreateSingleton(plugin, LoadMfaConfig);
}
#endregion
diff --git a/VNLib.Plugins.Essentials.Accounts/VNLib.Plugins.Essentials.Accounts.csproj b/VNLib.Plugins.Essentials.Accounts/VNLib.Plugins.Essentials.Accounts.csproj
index 15ac5e5..d710cfc 100644
--- a/VNLib.Plugins.Essentials.Accounts/VNLib.Plugins.Essentials.Accounts.csproj
+++ b/VNLib.Plugins.Essentials.Accounts/VNLib.Plugins.Essentials.Accounts.csproj
@@ -10,6 +10,8 @@
<PackageId>VNLib.Plugins.Essentials.Accounts</PackageId>
<Version>1.0.1.5</Version>
<PackageProjectUrl>https://www.vaughnnugent.com/resources</PackageProjectUrl>
+ <SignAssembly>True</SignAssembly>
+ <AssemblyOriginatorKeyFile>\\vaughnnugent.com\Internal\Folder Redirection\vman\Documents\Programming\Software\StrongNameingKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
diff --git a/VNLib.Plugins.Essentials.Content.Routing/Router.cs b/VNLib.Plugins.Essentials.Content.Routing/Router.cs
index 5170595..4dc320a 100644
--- a/VNLib.Plugins.Essentials.Content.Routing/Router.cs
+++ b/VNLib.Plugins.Essentials.Content.Routing/Router.cs
@@ -38,8 +38,6 @@ using VNLib.Plugins.Extensions.Loading.Events;
using VNLib.Plugins.Essentials.Content.Routing.Model;
using static VNLib.Plugins.Essentials.Accounts.AccountManager;
-#nullable enable
-
namespace VNLib.Plugins.Essentials.Content.Routing
{
internal class Router : IPageRouter, IIntervalScheduleable
@@ -53,7 +51,7 @@ namespace VNLib.Plugins.Essentials.Content.Routing
public Router(PluginBase plugin)
{
Store = new(plugin.GetContextOptions());
- _ = plugin.ScheduleInterval(this, TimeSpan.FromSeconds(30));
+ plugin.ScheduleInterval(this, TimeSpan.FromSeconds(30));
RouteTable = new();
}
diff --git a/VNLib.Plugins.Essentials.Content.Routing/VNLib.Plugins.Essentials.Content.Routing.csproj b/VNLib.Plugins.Essentials.Content.Routing/VNLib.Plugins.Essentials.Content.Routing.csproj
index c0188fa..30c8fd4 100644
--- a/VNLib.Plugins.Essentials.Content.Routing/VNLib.Plugins.Essentials.Content.Routing.csproj
+++ b/VNLib.Plugins.Essentials.Content.Routing/VNLib.Plugins.Essentials.Content.Routing.csproj
@@ -7,6 +7,8 @@
<Copyright>Copyright © 2022 Vaughn Nugent</Copyright>
<PackageProjectUrl>https://www.vaughnnugent.com</PackageProjectUrl>
<AssemblyName>PageRouter</AssemblyName>
+ <SignAssembly>True</SignAssembly>
+ <AssemblyOriginatorKeyFile>\\vaughnnugent.com\Internal\Folder Redirection\vman\Documents\Programming\Software\StrongNameingKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<!-- Resolve nuget dll files and store them in the output dir -->
diff --git a/VNLib.Plugins.Essentials.SocialOauth/VNLib.Plugins.Essentials.SocialOauth.csproj b/VNLib.Plugins.Essentials.SocialOauth/VNLib.Plugins.Essentials.SocialOauth.csproj
index 56e3068..25abcb8 100644
--- a/VNLib.Plugins.Essentials.SocialOauth/VNLib.Plugins.Essentials.SocialOauth.csproj
+++ b/VNLib.Plugins.Essentials.SocialOauth/VNLib.Plugins.Essentials.SocialOauth.csproj
@@ -7,7 +7,9 @@
<Version>1.0.1.5</Version>
<Copyright>Copyright © 2022 Vaughn Nugent</Copyright>
<PackageProjectUrl>https://www.vaughnnugent.com/resources</PackageProjectUrl>
- <AssemblyName>SocialOauth</AssemblyName>
+ <AssemblyName>SocialOauth</AssemblyName>
+ <SignAssembly>True</SignAssembly>
+ <AssemblyOriginatorKeyFile>\\vaughnnugent.com\Internal\Folder Redirection\vman\Documents\Programming\Software\StrongNameingKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>