diff --git a/src/ProtonVPN.Common/Helpers/RandomStrings.cs b/src/ProtonVPN.Crypto/RandomStrings.cs similarity index 70% rename from src/ProtonVPN.Common/Helpers/RandomStrings.cs rename to src/ProtonVPN.Crypto/RandomStrings.cs index e97ad3e8e..6418d971f 100644 --- a/src/ProtonVPN.Common/Helpers/RandomStrings.cs +++ b/src/ProtonVPN.Crypto/RandomStrings.cs @@ -18,24 +18,26 @@ */ using System; +using Org.BouncyCastle.Security; -namespace ProtonVPN.Common.Helpers +namespace ProtonVPN.Crypto { - /// - /// Generates random alphanumeric strings. - /// + /// Generates random alphanumeric strings. public class RandomStrings { - private readonly Random _random = new Random(); + private readonly SecureRandom _random = new(); public string RandomString(int length) { - Ensure.IsTrue(length >= 0); + if (length < 0) + { + throw new ArgumentException($"RandomString length can't be a negative number but is {length}."); + } const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - var randomChars = new char[length]; + char[] randomChars = new char[length]; - for (var i = 0; i < randomChars.Length; i++) + for (int i = 0; i < randomChars.Length; i++) { randomChars[i] = chars[_random.Next(chars.Length)]; } diff --git a/src/ProtonVPN.Vpn/Connection/OpenVpnConnection.cs b/src/ProtonVPN.Vpn/Connection/OpenVpnConnection.cs index 3885db6ed..f769b2a4f 100644 --- a/src/ProtonVPN.Vpn/Connection/OpenVpnConnection.cs +++ b/src/ProtonVPN.Vpn/Connection/OpenVpnConnection.cs @@ -25,7 +25,6 @@ using System.Threading.Tasks; using ProtonVPN.Common; using ProtonVPN.Common.Configuration; -using ProtonVPN.Common.Helpers; using ProtonVPN.Common.Logging; using ProtonVPN.Common.Logging.Categorization.Events.ConnectionLogs; using ProtonVPN.Common.Logging.Categorization.Events.ConnectLogs; @@ -34,6 +33,7 @@ using ProtonVPN.Common.OS.Net; using ProtonVPN.Common.Threading; using ProtonVPN.Common.Vpn; +using ProtonVPN.Crypto; using ProtonVPN.Vpn.Common; using ProtonVPN.Vpn.Management; using ProtonVPN.Vpn.OpenVpn; diff --git a/src/Tests/ProtonVPN.Crypto.Tests/ProtonVPN.Crypto.Tests.csproj b/src/Tests/ProtonVPN.Crypto.Tests/ProtonVPN.Crypto.Tests.csproj index 48eb56061..6c352ce62 100644 --- a/src/Tests/ProtonVPN.Crypto.Tests/ProtonVPN.Crypto.Tests.csproj +++ b/src/Tests/ProtonVPN.Crypto.Tests/ProtonVPN.Crypto.Tests.csproj @@ -12,6 +12,7 @@ + 2.2.10 diff --git a/src/Tests/ProtonVPN.Common.Tests/Helpers/RandomStringsTest.cs b/src/Tests/ProtonVPN.Crypto.Tests/RandomStringsTest.cs similarity index 94% rename from src/Tests/ProtonVPN.Common.Tests/Helpers/RandomStringsTest.cs rename to src/Tests/ProtonVPN.Crypto.Tests/RandomStringsTest.cs index 518b4cc8a..f11d7b681 100644 --- a/src/Tests/ProtonVPN.Common.Tests/Helpers/RandomStringsTest.cs +++ b/src/Tests/ProtonVPN.Crypto.Tests/RandomStringsTest.cs @@ -20,9 +20,8 @@ using System; using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; -using ProtonVPN.Common.Helpers; -namespace ProtonVPN.Common.Tests.Helpers +namespace ProtonVPN.Crypto.Tests { [TestClass] public class ManagementPasswordsTest @@ -30,7 +29,7 @@ public class ManagementPasswordsTest [DataTestMethod] [DataRow(0)] [DataRow(1)] - [DataRow(10)] + [DataRow(16)] public void Password_ShouldHave_CorrectLength(int length) { // Arrange