diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml index 127615744..6ed6e0b63 100644 --- a/.github/workflows/dotnet-core.yml +++ b/.github/workflows/dotnet-core.yml @@ -32,7 +32,6 @@ jobs: with: path: | ~/.nuget/packages - !~/.nuget/packages/argon2.bindings !~/.nuget/packages/zlib.bindings ${{ github.workspace }}/Projects/*/obj/project.assets.json ${{ github.workspace }}/Projects/*/obj/project.nuget.cache @@ -40,17 +39,6 @@ jobs: key: ${{ matrix.os }}-nuget-cache-v6-${{ hashFiles('**/packages.lock.json') }} restore-keys: | ${{ matrix.os }}-nuget-cache-v3 - - name: Argon2 Library Cache - id: argon2-cache - uses: actions/cache@v2 - with: - path: | - ~/.nuget/packages/argon2.bindings - ${{ github.workspace }}/Projects/Argon2/** - ${{ github.workspace }}/packages/Argon2.Bindings*.nupkg - key: ${{ matrix.os }}-argon2-cache-v6-${{ hashFiles('Projects/Argon2/*') }} - restore-keys: | - ${{ matrix.os }}-argon2-cache-v4 - name: ZLib Library Cache id: zlib-cache uses: actions/cache@v2 @@ -67,13 +55,8 @@ jobs: - name: Pack ZLib NuGet if: steps.zlib-cache.outputs.cache-hit != 'true' run: dotnet pack -c Release -o packages Projects/ZLib/ZLib.csproj - - name: Build Argon2 - run: dotnet build -c Release Projects/Argon2/Argon2.csproj - - name: Pack Argon2 NuGet - if: steps.argon2-cache.outputs.cache-hit != 'true' - run: dotnet pack -c Release -o packages Projects/Argon2/Argon2.csproj - name: Restore dependencies - if: steps.nuget-cache.outputs.cache-hit != 'true' || steps.argon2-cache.outputs.cache-hit != 'true' || steps.zlib-cache.outputs.cache-hit != 'true' + if: steps.nuget-cache.outputs.cache-hit != 'true' || steps.zlib-cache.outputs.cache-hit != 'true' run: dotnet restore --force-evaluate - name: Build Server run: dotnet build -c Release --no-restore Projects/Server/Server.csproj diff --git a/ModernUO.sln b/ModernUO.sln index 2301feaa2..63e8144f5 100644 --- a/ModernUO.sln +++ b/ModernUO.sln @@ -2,8 +2,6 @@ # Visual Studio Version 16 VisualStudioVersion = 16.0.29102.190 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Argon2", "Projects\Argon2\Argon2.csproj", "{97150E9D-5561-4D3C-9B78-E795544507D0}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "Projects\Server\Server.csproj", "{5E93BB35-3661-4822-9A8A-859726BAD87F}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UOContent", "Projects\UOContent\UOContent.csproj", "{83CF2484-BCCB-4B7C-9C5F-7AB43AEA5E8F}" @@ -45,12 +43,6 @@ Global {3C4797F9-603E-44EF-8E8C-9275CC9EA74B}.Debug|x64.Build.0 = Debug|x64 {3C4797F9-603E-44EF-8E8C-9275CC9EA74B}.Release|x64.ActiveCfg = Release|x64 {3C4797F9-603E-44EF-8E8C-9275CC9EA74B}.Release|x64.Build.0 = Release|x64 - {97150E9D-5561-4D3C-9B78-E795544507D0}.Analyze|x64.ActiveCfg = Analyze|x64 - {97150E9D-5561-4D3C-9B78-E795544507D0}.Analyze|x64.Build.0 = Analyze|x64 - {97150E9D-5561-4D3C-9B78-E795544507D0}.Debug|x64.ActiveCfg = Debug|x64 - {97150E9D-5561-4D3C-9B78-E795544507D0}.Debug|x64.Build.0 = Debug|x64 - {97150E9D-5561-4D3C-9B78-E795544507D0}.Release|x64.ActiveCfg = Release|x64 - {97150E9D-5561-4D3C-9B78-E795544507D0}.Release|x64.Build.0 = Release|x64 {3B030CD2-DB29-4BC2-9C90-D90804B30757}.Analyze|x64.ActiveCfg = Analyze|x64 {3B030CD2-DB29-4BC2-9C90-D90804B30757}.Analyze|x64.Build.0 = Analyze|x64 {3B030CD2-DB29-4BC2-9C90-D90804B30757}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/Projects/Argon2/Argon2.cs b/Projects/Argon2/Argon2.cs deleted file mode 100644 index 5a05d33b6..000000000 --- a/Projects/Argon2/Argon2.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System.Runtime.InteropServices; - -namespace System.Security.Cryptography -{ - internal interface IArgon2 - { - public Argon2Error Hash(uint t_cost, uint m_cost, uint parallelism, - ReadOnlySpan pwd, - ReadOnlySpan salt, - Span hash, - Span encoded, - int type, int version); - - Argon2Error Verify(ReadOnlySpan encoded, ReadOnlySpan pwd, int pwdlen, int type); - - // TODO: Change str to use ReadOnlySpan then convert to pointer later - Argon2Error Decode(Argon2Context ctx, ReadOnlySpan str, int type); - } - - internal static class Argon2 - { - internal static readonly bool IsDarwin = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); - internal static readonly bool IsFreeBSD = RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD); - internal static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); - internal static readonly bool IsUnix = IsLinux || IsDarwin || IsFreeBSD; - - internal static readonly IArgon2 Library = IsUnix ? (IArgon2)new UnixArgon2() : new WindowsArgon2(); - } - - internal class WindowsArgon2 : IArgon2 - { - public Argon2Error Hash(uint t_cost, uint m_cost, uint parallelism, - ReadOnlySpan pwd, - ReadOnlySpan salt, - Span hash, - Span encoded, - int type, int version) => - SafeNativeMethods.argon2_hash(t_cost, m_cost, parallelism, - in pwd.GetPinnableReference(), pwd.Length, - in salt.GetPinnableReference(), salt.Length, - ref hash.GetPinnableReference(), hash.Length, - ref encoded.GetPinnableReference(), encoded.Length, - type, version - ); - - public Argon2Error Verify(ReadOnlySpan encoded, ReadOnlySpan pwd, int pwdlen, int type) => - SafeNativeMethods.argon2_verify(in encoded.GetPinnableReference(), in pwd.GetPinnableReference(), pwdlen, type); - - public Argon2Error Decode(Argon2Context ctx, ReadOnlySpan str, int type) => - SafeNativeMethods.decode_string(ctx, in str.GetPinnableReference(), type); - - internal static class SafeNativeMethods - { - [DllImport("libargon2.dll", EntryPoint = "argon2_hash", CallingConvention = CallingConvention.Cdecl)] - internal static extern Argon2Error argon2_hash(uint t_cost, uint m_cost, uint parallelism, - in byte pwd, int pwdlen, - in byte salt, int saltlen, - ref byte hash, int hashlen, - ref byte encoded, int encodedlen, - int type, int version - ); - - [DllImport("libargon2.dll", EntryPoint = "argon2_verify", CallingConvention = CallingConvention.Cdecl)] - internal static extern Argon2Error argon2_verify(in byte encoded, in byte pwd, int pwdlen, int type); - - [DllImport("libargon2.dll", EntryPoint = "decode_string", CallingConvention = CallingConvention.Cdecl)] - internal static extern Argon2Error decode_string(Argon2Context ctx, in byte str, int type); - } - } - - internal class UnixArgon2 : IArgon2 - { - public Argon2Error Hash(uint t_cost, uint m_cost, uint parallelism, - ReadOnlySpan pwd, - ReadOnlySpan salt, - Span hash, - Span encoded, - int type, int version) => - SafeNativeMethods.argon2_hash(t_cost, m_cost, parallelism, - in pwd.GetPinnableReference(), pwd.Length, - in salt.GetPinnableReference(), salt.Length, - ref hash.GetPinnableReference(), hash.Length, - ref encoded.GetPinnableReference(), encoded.Length, - type, version - ); - - public Argon2Error Verify(ReadOnlySpan encoded, ReadOnlySpan pwd, int pwdlen, int type) => - SafeNativeMethods.argon2_verify(in encoded.GetPinnableReference(), in pwd.GetPinnableReference(), pwdlen, type); - - public Argon2Error Decode(Argon2Context ctx, ReadOnlySpan str, int type) => - SafeNativeMethods.decode_string(ctx, in str.GetPinnableReference(), type); - - internal static class SafeNativeMethods - { - [DllImport("argon2", EntryPoint = "argon2_hash")] - internal static extern Argon2Error argon2_hash(uint t_cost, uint m_cost, uint parallelism, - in byte pwd, int pwdlen, - in byte salt, int saltlen, - ref byte hash, int hashlen, - ref byte encoded, int encodedlen, - int type, int version - ); - - [DllImport("argon2", EntryPoint = "argon2_verify")] - internal static extern Argon2Error argon2_verify(in byte encoded, in byte pwd, int pwdlen, int type); - - [DllImport("argon2", EntryPoint = "decode_string")] - internal static extern Argon2Error decode_string(Argon2Context ctx, in byte str, int type); - } - } -} diff --git a/Projects/Argon2/Argon2.csproj b/Projects/Argon2/Argon2.csproj deleted file mode 100644 index c42829969..000000000 --- a/Projects/Argon2/Argon2.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - 1.2.7 - System.Security.Cryptography - Argon2.Bindings - true - false - true - Debug;Release;Analyze - 1.2.7 - - - - true - runtimes/win-x64/native - Always - - - true - runtimes/osx-x64/native - Always - - - true - runtimes/linux-x64/native - Always - - - diff --git a/Projects/Argon2/Argon2.nuspec b/Projects/Argon2/Argon2.nuspec deleted file mode 100644 index bf03a1491..000000000 --- a/Projects/Argon2/Argon2.nuspec +++ /dev/null @@ -1,15 +0,0 @@ - - - - Argon2.Bindings - 1.1.8 - Kamron Batman - Kamron Batman - MIT - https://github.com/modernUO/ModernUO - false - Argon2 C# Bindings for ModernUO - Updated to use spans/pointers - Copyright 2020 - - diff --git a/Projects/Argon2/Argon2Context.cs b/Projects/Argon2/Argon2Context.cs deleted file mode 100644 index 25a5b030e..000000000 --- a/Projects/Argon2/Argon2Context.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Runtime.InteropServices; - -namespace System.Security.Cryptography -{ - [StructLayout(LayoutKind.Sequential)] - internal class Argon2Context - { - public IntPtr Out; - public uint OutLen; - - public IntPtr Pwd; - public uint PwdLen; - - public IntPtr Salt; - public uint SaltLen; - - public IntPtr Secret; - public uint SecretLen; - - public IntPtr AssocData; - public uint AssocDataLen; - - public uint TimeCost; - public uint MemoryCost; - public uint Lanes; - public uint Threads; - - public IntPtr AllocateCallback; - public IntPtr FreeCallback; - - public uint Flags; - } -} diff --git a/Projects/Argon2/Argon2Error.cs b/Projects/Argon2/Argon2Error.cs deleted file mode 100644 index bdb645236..000000000 --- a/Projects/Argon2/Argon2Error.cs +++ /dev/null @@ -1,83 +0,0 @@ -namespace System.Security.Cryptography -{ - /// - /// An enumeration of the possible error codes which are returned from Daniel Dinu and - /// Dmitry Khovratovich's Argon2 library. - /// - /// Some of these error conditions cannot be reached while using the C# PasswordHasher wrapper - /// - public enum Argon2Error - { - /// - /// The operation was successful - /// - OK = 0, - - /// - /// The output hash length is less than 4 bytes - /// - OUTPUT_TOO_SHORT = -2, - - /// - /// The salt is less than 8 bytes - /// - SALT_TOO_SHORT = -6, - - /// - /// The salt is too big - /// - SALT_TOO_LONG = -7, - - /// - /// The time cost is less than 1 - /// - TIME_TOO_SMALL = -12, - - /// - /// The memory cost is less than 8 (KiB) - /// - MEMORY_TOO_LITTLE = -14, - /// - /// The memory cost is greater than 2^21 (KiB) (2 GiB) - /// - MEMORY_TOO_MUCH = -15, - - /// - /// The parallelism is less than 1 - /// - LANES_TOO_FEW = -16, - /// - /// The parallelism is greater than 16,777,215 - /// - LANES_TOO_MANY = -17, - - /// - /// Memory allocation failed - /// - MEMORY_ALLOCATION_ERROR = -22, - - /// - /// The parallelism is less than 1 - /// - THREADS_TOO_FEW = -28, - /// - /// The parallelism is greater than 16,777,215 - /// - THREADS_TOO_MANY = -29, - - /// - /// This will not be returned from the C# PasswordHasher wrapper - /// - DECODING_FAIL = -32, - - /// - /// Unable to create the number of threads requested - /// - THREAD_FAIL = -33, - - /// - /// This will not be returned from the C# PasswordHasher wrapper - /// - VERIFY_MISMATCH = -35 - } -} diff --git a/Projects/Argon2/Argon2Exception.cs b/Projects/Argon2/Argon2Exception.cs deleted file mode 100644 index b7a7a2ad6..000000000 --- a/Projects/Argon2/Argon2Exception.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace System.Security.Cryptography -{ - /// - /// An exception class to wrap the errors returned by Daniel Dinu and Dmitry Khovratovich's Argon2 library. - /// - /// Except through very unusual conditions, the only exceptions which could be thrown from PasswordHasher - /// are Argon2Exception, ArgumentNullException, DllNotFoundException (if libargon2.dll is not found) - /// - public class Argon2Exception : Exception - { - /// - /// Construct an Argon2Exception with the specified Argon2 error code - /// Which method the Argon2Exception originated from - /// The error returned from the Argon2 library - /// - public Argon2Exception(string action, Argon2Error error) : base($"Error during Argon2 {action}: ({(int)error}) {error}") {} - } -} diff --git a/Projects/Argon2/Argon2PasswordHasher.cs b/Projects/Argon2/Argon2PasswordHasher.cs deleted file mode 100644 index 6f72e482f..000000000 --- a/Projects/Argon2/Argon2PasswordHasher.cs +++ /dev/null @@ -1,279 +0,0 @@ -using System.Runtime.InteropServices; -using System.Text; - -namespace System.Security.Cryptography -{ - /// - /// PasswordHasher is a class for creating Argon2 hashes and verifying them. This is a wrapper around - /// Daniel Dinu and Dmitry Khovratovich's Argon2 library. - /// - public class Argon2PasswordHasher - { - private static RandomNumberGenerator m_Rng; - - /// - /// How many iterations of the Argon2 hash to perform - /// - public uint TimeCost { get; set; } - - /// - /// How much memory to use while hashing in kibibytes (KiB) - /// - public uint MemoryCost { get; set; } - - /// - /// How many threads to use while hashing - /// - public uint Parallelism { get; set; } - - /// - /// The type of Argon2 hashing algorithm to use - /// Argon2d - The memory access is dependent upon the hash value (vulnerable to side-channel attacks) - /// Argon2i - The memory access is independent upon the hash value (safe from side-channel atacks) - /// - public Argon2Type ArgonType { get; set; } - - /// - /// Length of the generated raw hash in bytes - /// - public uint HashLength { get; set; } - - /// - /// How strings should be decoded when passed to the Hash method. - /// The default is Encoding.UTF8. - /// - public Encoding StringEncoding { get; set; } - - /// - /// Randomizer used to generate salts - /// - public RandomNumberGenerator Rng { get; set; } - - /// - /// Initialize the Argon2 PasswordHasher with default performance and algorithm settings based upon the environment the hashing will be used in. - /// You should perform your own profiling to determine what the parameters should be for your specific usage; however, this attempts to provide - /// some reasonable defaults. - /// - public Argon2PasswordHasher(RandomNumberGenerator rng = null) - { - TimeCost = 3; - MemoryCost = 8192; - Parallelism = 1; - ArgonType = Argon2Type.Argon2i; - HashLength = 32; - StringEncoding = Encoding.UTF8; - Rng = rng ?? (m_Rng ??= new RNGCryptoServiceProvider()); - } - - /// - /// Hash the password using Argon2 with a cryptographically-secure, random, 16-byte salt. - /// This is the only overload of the Hash method that the typical user will need to use for password storage. The other overloads are provided for interoperability purposes. - /// Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. - /// A string representing the password to be hashed. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) - /// A formatted string representing the hashed password, encoded with the parameters used to perform the hash - /// - public string Hash(ReadOnlySpan password) - { - Span salt = stackalloc byte[16]; - Rng.GetBytes(salt); - return Hash(password, salt); - } - - /// - /// Hash the raw password bytes using Argon2 with the specified salt bytes. - /// Unless you need to specify your own salt for interoperability purposes, prefer the Hash(byte[] password) overload instead. - /// Do not compare two Argon2 hashes directly. Instead, use the Verify or VerifyAndUpdate methods. - /// The raw bytes of the password to be hashed - /// The raw salt bytes to be used for the hash. The salt must be at least 8 bytes. - /// A formatted string representing the hashed password, encoded with the parameters used to perform the hash - /// - public string Hash(ReadOnlySpan password, ReadOnlySpan salt) - { - Span hash = stackalloc byte[(int)HashLength]; - Span encoded = stackalloc byte[(int)(39 + ((HashLength + salt.Length) * 4 + 3) / 3)]; - Span passwordBytes = stackalloc byte[StringEncoding.GetByteCount(password)]; - StringEncoding.GetBytes(password, passwordBytes); - - var result = Argon2.Library.Hash( - TimeCost, - MemoryCost, - Parallelism, - passwordBytes, - salt, - hash, - encoded, - (int)ArgonType, - 0x13 - ); - - if (result != Argon2Error.OK) - throw new Argon2Exception("hashing", result); - - var firstNonNull = encoded.Length - 2; - while (encoded[firstNonNull] == 0) - firstNonNull--; - - return Encoding.ASCII.GetString(encoded.Slice(0, firstNonNull + 1)); - } - - /// - /// Hash the password using Argon2 with the specified salt. The HashRaw methods may be used for password-based key derivation. - /// Unless you're using HashRaw for key deriviation or for interoperability purposes, the Hash methods should be used in favor of the HashRaw methods. - /// The raw bytes of the password to be hashed - /// The raw salt bytes to be used for the hash. The salt must be at least 8 bytes. - /// A byte array containing only the resulting hash - /// - public void HashRaw(ReadOnlySpan password, ReadOnlySpan salt, Span hash) - { - Span passwordBytes = stackalloc byte[StringEncoding.GetByteCount(password)]; - StringEncoding.GetBytes(password, passwordBytes); - - var result = Argon2.Library.Hash( - TimeCost, - MemoryCost, - Parallelism, - passwordBytes, - salt, - hash, - null, - (int)ArgonType, - 0x13 - ); - - if (result != Argon2Error.OK) - throw new Argon2Exception("raw hashing", result); - } - - - /// - /// Hashes the password and verifies that the password results in the specified hash. - /// The ArgonType must of this PasswordHasher object must match what was used to generate expectedHash. - /// The other parameters (timeCost, etc.) do not need to match and the parameters embedded in the expectedHash will be used. - /// Hashing the password should result in this hash - /// The password to hash and compare its result to expectedHash. The password is first decoded into bytes using StringEncoding (default: Encoding.UTF8) - /// Whether the password results in the expectedHash when hashed - /// - public bool Verify(ReadOnlySpan expectedHash, ReadOnlySpan password) - { - Span expectedHashBytes = stackalloc byte[StringEncoding.GetByteCount(expectedHash)]; - StringEncoding.GetBytes(expectedHash, expectedHashBytes); - Span passwordBytes = stackalloc byte[StringEncoding.GetByteCount(password)]; - StringEncoding.GetBytes(password, passwordBytes); - return Verify(expectedHashBytes, passwordBytes); - } - - /// - /// Hashes the raw password bytes and verifies that the password results in the specified hash. - /// The ArgonType must of this PasswordHasher object must match what was used to generate expectedHash. - /// The other parameters (timeCost, etc.) do not need to match and the parameters embedded in the expectedHash will be used. - /// Hashing the password should result in this hash - /// The raw password bytes to hash and compare its result to expectedHash - /// Whether the password results in the expectedHash when hashed - /// - public bool Verify(ReadOnlySpan expectedHash, ReadOnlySpan password) - { - var result = Argon2.Library.Verify(expectedHash, password, password.Length, (int)ArgonType); - - if (result == Argon2Error.OK || result == Argon2Error.VERIFY_MISMATCH || result == Argon2Error.DECODING_FAIL) - return result == Argon2Error.OK; - - throw new Argon2Exception("verifying", result); - } - - /// - /// Hashes the password and verifies that the password results in the specified hash. (See Verify method) - /// If the password verification is successful, this method checks to see if the memory cost, time cost, and parallelism - /// match the parameters the PasswordHasher object was constructed with. If they do not much, then the password is rehashed - /// using the new parameters and the result is outputted via the newFormattedHash parameter. - /// Hashing the password should result in this hash - /// The raw password bytes to hash and compare its result to expectedHash - /// Whether the cost parameters of expectedHash differ from the PasswordHasher object and if the password was rehashed using th new parameters. This is always false if the password was incorrect. - /// If isUpdated is true, then newFormattedHash is the password hashed with the new cost parameters. If isUpdated is false, then newFormattedHash is expectedHash. - /// Whether the password results in the expectedHash when hashed - /// - public bool VerifyAndUpdate(ReadOnlySpan expectedHash, ReadOnlySpan password, out bool isUpdated, out string newFormattedHash) - { - bool verified = Verify(expectedHash, password); - - if (verified) - { - var hashMetadata = ExtractMetadata(expectedHash); - - if (hashMetadata.MemoryCost != MemoryCost || hashMetadata.TimeCost != TimeCost || hashMetadata.Parallelism != Parallelism) - { - isUpdated = true; - byte[] salt = hashMetadata.Salt; - newFormattedHash = Hash(password, salt); - return true; - } - } - - isUpdated = false; - newFormattedHash = expectedHash.ToString(); - return verified; - } - - /// - /// Extracts the memory cost, time cost, etc. used to generate the Argon2 hash. - /// An encoded Argon2 hash created by the Hash method - /// The hash metadata or null if the formattedHash was not a valid encoded Argon2 hash - /// - public static HashMetadata ExtractMetadata(ReadOnlySpan formattedHash) - { - var context = new Argon2Context - { - Out = Marshal.AllocHGlobal(formattedHash.Length), // ensure the space to hold the hash is long enough - OutLen = (uint)formattedHash.Length, - Pwd = Marshal.AllocHGlobal(1), - PwdLen = 1, - Salt = Marshal.AllocHGlobal(formattedHash.Length), // ensure the space to hold the salt is long enough - SaltLen = (uint)formattedHash.Length, - Secret = Marshal.AllocHGlobal(1), - SecretLen = 1, - AssocData = Marshal.AllocHGlobal(1), - AssocDataLen = 1, - TimeCost = 0, - MemoryCost = 0, - Lanes = 0, - Threads = 0 - }; - - try - { - var type = formattedHash.StartsWith("$argon2i") ? Argon2Type.Argon2i : Argon2Type.Argon2d; - formattedHash = $"{formattedHash.ToString()}\0"; - - Span bytes = stackalloc byte[formattedHash.Length]; - Encoding.ASCII.GetBytes(formattedHash, bytes); - - var result = Argon2.Library.Decode(context, bytes, (int)type); - - if (result != Argon2Error.OK) - return null; - - var salt = new byte[context.SaltLen]; - var hash = new byte[context.OutLen]; - Marshal.Copy(context.Salt, salt, 0, salt.Length); - Marshal.Copy(context.Out, hash, 0, hash.Length); - - return new HashMetadata - { - ArgonType = type, - MemoryCost = context.MemoryCost, - TimeCost = context.TimeCost, - Parallelism = context.Threads, - Salt = salt, - Hash = hash - }; - } - finally - { - Marshal.FreeHGlobal(context.Out); - Marshal.FreeHGlobal(context.Pwd); - Marshal.FreeHGlobal(context.Salt); - Marshal.FreeHGlobal(context.Secret); - Marshal.FreeHGlobal(context.AssocData); - } - } - } -} diff --git a/Projects/Argon2/Argon2Type.cs b/Projects/Argon2/Argon2Type.cs deleted file mode 100644 index 3195a90f9..000000000 --- a/Projects/Argon2/Argon2Type.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace System.Security.Cryptography -{ - /// - /// The type of Argon2 hashing algorithm to use. - /// - public enum Argon2Type - { - /// - /// The memory access is dependent upon the hash value (vulnerable to side-channel attacks) - /// - Argon2d = 0, - - /// - /// The memory access is independent upon the hash value (safe from side-channel atacks) - /// - Argon2i = 1 - } -} diff --git a/Projects/Argon2/HashMetadata.cs b/Projects/Argon2/HashMetadata.cs deleted file mode 100644 index a08995353..000000000 --- a/Projects/Argon2/HashMetadata.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace System.Security.Cryptography -{ - /// - /// HashMetadata represents the information stored in the encoded Argon2 format - /// - public class HashMetadata - { - /// - /// The type of Argon2 hashing algorithm to use - /// Argon2d - The memory access is dependent upon the hash value (vulnerable to side-channel attacks) - /// Argon2i - The memory access is independent upon the hash value (safe from side-channel atacks) - /// - public Argon2Type ArgonType { get; set; } - - /// - /// How much memory to use while hashing in kibibytes (KiB) - /// - public uint MemoryCost { get; set; } - - /// - /// How many iterations of the Argon2 hash to perform - /// - public uint TimeCost { get; set; } - - /// - /// How many threads to use while hashing - /// - public uint Parallelism { get; set; } - - /// - /// The raw bytes of the salt - /// - public byte[] Salt { get; set; } - - /// - /// The raw bytes of the hash - /// - public byte[] Hash { get; set; } - - - /// - /// A base-64 encoded string of the salt, minus the padding (=) characters - /// - public string GetBase64Salt() => Convert.ToBase64String(Salt).Replace("=", ""); - - /// - /// A base-64 encoded string of the hash, minus the padding (=) characters - /// - public string GetBase64Hash() => Convert.ToBase64String(Hash).Replace("=", ""); - - - /// - /// Converts HashMetadata back into the original Argon2 formatted string. - /// - public override string ToString() => - $"$argon2{(ArgonType == Argon2Type.Argon2i ? "i" : "d")}$v=19$m={MemoryCost},t={TimeCost},p={Parallelism}${GetBase64Salt()}${GetBase64Hash()}"; - } -} diff --git a/Projects/Argon2/packages.lock.json b/Projects/Argon2/packages.lock.json deleted file mode 100644 index 9c9abd993..000000000 --- a/Projects/Argon2/packages.lock.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": 1, - "dependencies": { - ".NETCoreApp,Version=v3.1": {}, - ".NETCoreApp,Version=v3.1/linux-x64": {}, - ".NETCoreApp,Version=v3.1/osx-x64": {}, - ".NETCoreApp,Version=v3.1/win-x64": {} - } -} \ No newline at end of file diff --git a/Projects/Argon2/runtimes/linux-x64/native/libargon2.so b/Projects/Argon2/runtimes/linux-x64/native/libargon2.so deleted file mode 100755 index 1097b8dcd..000000000 Binary files a/Projects/Argon2/runtimes/linux-x64/native/libargon2.so and /dev/null differ diff --git a/Projects/Argon2/runtimes/osx-x64/native/libargon2.dylib b/Projects/Argon2/runtimes/osx-x64/native/libargon2.dylib deleted file mode 100755 index 0b2ae9205..000000000 Binary files a/Projects/Argon2/runtimes/osx-x64/native/libargon2.dylib and /dev/null differ diff --git a/Projects/Argon2/runtimes/win-x64/native/libargon2.dll b/Projects/Argon2/runtimes/win-x64/native/libargon2.dll deleted file mode 100755 index da586a221..000000000 Binary files a/Projects/Argon2/runtimes/win-x64/native/libargon2.dll and /dev/null differ diff --git a/Projects/Server.Tests/packages.lock.json b/Projects/Server.Tests/packages.lock.json index 5d44ca9b9..7e772b14b 100644 --- a/Projects/Server.Tests/packages.lock.json +++ b/Projects/Server.Tests/packages.lock.json @@ -1184,7 +1184,7 @@ "ZLib.Bindings": { "type": "Transitive", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "ModernUO": { "type": "Project", @@ -2068,7 +2068,7 @@ "ZLib.Bindings": { "type": "Transitive", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" } }, ".NETCoreApp,Version=v3.1/osx-x64": { @@ -2942,7 +2942,7 @@ "ZLib.Bindings": { "type": "Transitive", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" } }, ".NETCoreApp,Version=v3.1/win-x64": { @@ -3799,7 +3799,7 @@ "ZLib.Bindings": { "type": "Transitive", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" } } } diff --git a/Projects/Server/packages.lock.json b/Projects/Server/packages.lock.json index 2759f8dce..437f618b4 100644 --- a/Projects/Server/packages.lock.json +++ b/Projects/Server/packages.lock.json @@ -46,7 +46,7 @@ "type": "Direct", "requested": "[1.0.2, )", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "Libuv": { "type": "Transitive", @@ -116,7 +116,7 @@ "type": "Direct", "requested": "[1.0.2, )", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "Libuv": { "type": "Transitive", @@ -132,7 +132,7 @@ "type": "Direct", "requested": "[1.0.2, )", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "Libuv": { "type": "Transitive", @@ -148,7 +148,7 @@ "type": "Direct", "requested": "[1.0.2, )", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "Libuv": { "type": "Transitive", diff --git a/Projects/UOContent.Tests/packages.lock.json b/Projects/UOContent.Tests/packages.lock.json index 65f9742fb..412f5c164 100644 --- a/Projects/UOContent.Tests/packages.lock.json +++ b/Projects/UOContent.Tests/packages.lock.json @@ -40,8 +40,8 @@ }, "Argon2.Bindings": { "type": "Transitive", - "resolved": "1.2.7", - "contentHash": "ZmxtDx9RwHdRBHSq8d97VNHF0el1OAQzWQAtMyT+F/1KApVjBpPcqXVr4eAvAp8qQqBSl5y3WhEvBMBRBdkpgw==" + "resolved": "1.3.0", + "contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ==" }, "Libuv": { "type": "Transitive", @@ -1330,7 +1330,7 @@ "ZLib.Bindings": { "type": "Transitive", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "ModernUO": { "type": "Project", @@ -1345,7 +1345,7 @@ "uocontent": { "type": "Project", "dependencies": { - "Argon2.Bindings": "1.2.7", + "Argon2.Bindings": "1.3.0", "MailKit": "2.7.0", "Microsoft.AspNetCore.Connections.Abstractions": "3.1.5", "Microsoft.Extensions.DependencyInjection.Abstractions": "3.1.5", @@ -1358,8 +1358,8 @@ ".NETCoreApp,Version=v3.1/linux-x64": { "Argon2.Bindings": { "type": "Transitive", - "resolved": "1.2.7", - "contentHash": "ZmxtDx9RwHdRBHSq8d97VNHF0el1OAQzWQAtMyT+F/1KApVjBpPcqXVr4eAvAp8qQqBSl5y3WhEvBMBRBdkpgw==" + "resolved": "1.3.0", + "contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ==" }, "Libuv": { "type": "Transitive", @@ -2242,14 +2242,14 @@ "ZLib.Bindings": { "type": "Transitive", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" } }, ".NETCoreApp,Version=v3.1/osx-x64": { "Argon2.Bindings": { "type": "Transitive", - "resolved": "1.2.7", - "contentHash": "ZmxtDx9RwHdRBHSq8d97VNHF0el1OAQzWQAtMyT+F/1KApVjBpPcqXVr4eAvAp8qQqBSl5y3WhEvBMBRBdkpgw==" + "resolved": "1.3.0", + "contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ==" }, "Libuv": { "type": "Transitive", @@ -3132,14 +3132,14 @@ "ZLib.Bindings": { "type": "Transitive", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" } }, ".NETCoreApp,Version=v3.1/win-x64": { "Argon2.Bindings": { "type": "Transitive", - "resolved": "1.2.7", - "contentHash": "ZmxtDx9RwHdRBHSq8d97VNHF0el1OAQzWQAtMyT+F/1KApVjBpPcqXVr4eAvAp8qQqBSl5y3WhEvBMBRBdkpgw==" + "resolved": "1.3.0", + "contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ==" }, "Libuv": { "type": "Transitive", @@ -4019,7 +4019,7 @@ "ZLib.Bindings": { "type": "Transitive", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" } } } diff --git a/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs b/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs index b79d5cafa..ecf1be8e0 100644 --- a/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs +++ b/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs @@ -26,7 +26,9 @@ namespace Server.Accounting.Security public class Argon2PasswordProtection : IPasswordProtection { public static IPasswordProtection Instance = new Argon2PasswordProtection(); - private Argon2PasswordHasher m_PasswordHasher = new Argon2PasswordHasher(RandomProviders.SecureProvider as RandomNumberGenerator); + private Argon2PasswordHasher m_PasswordHasher = new Argon2PasswordHasher( + rng: RandomProviders.SecureProvider as RandomNumberGenerator + ); public string EncryptPassword(string plainPassword) => m_PasswordHasher.Hash(plainPassword); diff --git a/Projects/UOContent/UOContent.csproj b/Projects/UOContent/UOContent.csproj index 26077283e..3bcd8e3b5 100644 --- a/Projects/UOContent/UOContent.csproj +++ b/Projects/UOContent/UOContent.csproj @@ -66,9 +66,10 @@ + - + diff --git a/Projects/UOContent/packages.lock.json b/Projects/UOContent/packages.lock.json index 5681950c3..bdc0444c5 100644 --- a/Projects/UOContent/packages.lock.json +++ b/Projects/UOContent/packages.lock.json @@ -4,9 +4,9 @@ ".NETCoreApp,Version=v3.1": { "Argon2.Bindings": { "type": "Direct", - "requested": "[1.2.7, )", - "resolved": "1.2.7", - "contentHash": "ZmxtDx9RwHdRBHSq8d97VNHF0el1OAQzWQAtMyT+F/1KApVjBpPcqXVr4eAvAp8qQqBSl5y3WhEvBMBRBdkpgw==" + "requested": "[1.3.0, )", + "resolved": "1.3.0", + "contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ==" }, "MailKit": { "type": "Direct", @@ -58,7 +58,7 @@ "type": "Direct", "requested": "[1.0.2, )", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "Libuv": { "type": "Transitive", @@ -799,15 +799,15 @@ ".NETCoreApp,Version=v3.1/linux-x64": { "Argon2.Bindings": { "type": "Direct", - "requested": "[1.2.7, )", - "resolved": "1.2.7", - "contentHash": "ZmxtDx9RwHdRBHSq8d97VNHF0el1OAQzWQAtMyT+F/1KApVjBpPcqXVr4eAvAp8qQqBSl5y3WhEvBMBRBdkpgw==" + "requested": "[1.3.0, )", + "resolved": "1.3.0", + "contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ==" }, "ZLib.Bindings": { "type": "Direct", "requested": "[1.0.2, )", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "Libuv": { "type": "Transitive", @@ -1502,15 +1502,15 @@ ".NETCoreApp,Version=v3.1/osx-x64": { "Argon2.Bindings": { "type": "Direct", - "requested": "[1.2.7, )", - "resolved": "1.2.7", - "contentHash": "ZmxtDx9RwHdRBHSq8d97VNHF0el1OAQzWQAtMyT+F/1KApVjBpPcqXVr4eAvAp8qQqBSl5y3WhEvBMBRBdkpgw==" + "requested": "[1.3.0, )", + "resolved": "1.3.0", + "contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ==" }, "ZLib.Bindings": { "type": "Direct", "requested": "[1.0.2, )", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "Libuv": { "type": "Transitive", @@ -2205,15 +2205,15 @@ ".NETCoreApp,Version=v3.1/win-x64": { "Argon2.Bindings": { "type": "Direct", - "requested": "[1.2.7, )", - "resolved": "1.2.7", - "contentHash": "ZmxtDx9RwHdRBHSq8d97VNHF0el1OAQzWQAtMyT+F/1KApVjBpPcqXVr4eAvAp8qQqBSl5y3WhEvBMBRBdkpgw==" + "requested": "[1.3.0, )", + "resolved": "1.3.0", + "contentHash": "cxRZ+nwH33QozaFBAftjctf9PoNEXgcEI5dBHHDkWI24EwCeOXRp0M+h5muavQADfxIvPG9o4FNCSnP7VkV6wQ==" }, "ZLib.Bindings": { "type": "Direct", "requested": "[1.0.2, )", "resolved": "1.0.2", - "contentHash": "oMnRfnRHzfboCS/SXUrrqbDVtM/9h5LkHkB8GuyUq70BYkJRza7CNZxLR+F6IKOTNDcDO68VVCID4DA5Sj8c4Q==" + "contentHash": "KlvJLY55UYpwlxbiX+lJbTuaMWBK3mja3BC3GzTlCA3uHRYxsllL9uYqpe4poFe6l8NMBS/k759+ns8pbeXeMg==" }, "Libuv": { "type": "Transitive",