1
0
mirror of https://github.com/XFox111/SimpleOTP.git synced 2026-04-22 08:00:45 +03:00

Fixed invalid code generation on formatted secrets

This commit is contained in:
2021-12-05 20:44:17 +00:00
committed by GitHub
parent 4c63be6389
commit 42f968171b
3 changed files with 28 additions and 4 deletions
+25
View File
@@ -41,6 +41,31 @@ namespace SimpleOTP.Test
Assert.AreEqual(293657, code.Code);
}
/// <summary>
/// Test time-based OTP generator with customly formatted secret.
/// </summary>
[TestMethod("Secret format test")]
public void FormatTest()
{
Console.Write("Uppercase space-separated: ");
var config = totpConfig with { Secret = "JBSW Y3DP EHPK 3PXP" };
var code = OTPService.GenerateCode(ref config, time);
Assert.AreEqual(160102, code.Code);
Console.WriteLine("Passed.");
Console.Write("Lowercase space-separated: ");
config = totpConfig with { Secret = "jbsw y3dp ehpk 3pxp" };
code = OTPService.GenerateCode(ref config, time);
Assert.AreEqual(160102, code.Code);
Console.WriteLine("Passed.");
Console.Write("Lowercase: ");
config = totpConfig with { Secret = "jbswy3dpehpk3pxp" };
code = OTPService.GenerateCode(ref config, time);
Assert.AreEqual(160102, code.Code);
Console.WriteLine("Passed.");
}
/// <summary>
/// Test HOTP generator with pre-calculated code.
/// </summary>
+1 -1
View File
@@ -48,7 +48,7 @@ namespace SimpleOTP
/// </returns>
public static OTPCode GenerateCode(ref OTPConfiguration target, DateTime date)
{
byte[] keyBytes = Base32Encoder.Decode(target.Secret);
byte[] keyBytes = Base32Encoder.Decode(target.Secret.ToUpperInvariant().Replace(" ", string.Empty));
long counter = target.Type == OTPType.HOTP ? target.Counter : GetCurrentCounter(date.ToUniversalTime(), (int)target.Period.TotalSeconds);
byte[] counterBytes = BitConverter.GetBytes(counter);
+2 -3
View File
@@ -12,7 +12,7 @@
<PropertyGroup>
<PackageId>SimpleOTP</PackageId>
<AssemblyName>SimpleOTP</AssemblyName>
<Version>1.2.2</Version>
<Version>1.2.3</Version>
<Description>.NET library for TOTP/HOTP implementation on server (ASP.NET) or client (Xamarin) side</Description>
<Authors>Eugene Fox</Authors>
<Company>FoxDev Studio</Company>
@@ -22,8 +22,7 @@
<RepositoryUrl>https://github.com/XFox111/SimpleOTP</RepositoryUrl>
<NeutralLanguage>en-US</NeutralLanguage>
<PackageTags>otp;totp;dotnet;hotp;authenticator;2fa;mfa;security;oath</PackageTags>
<PackageReleaseNotes>- Fixed Base32 encoder
- Updated NuGet dependency packages</PackageReleaseNotes>
<PackageReleaseNotes>- Fixed invalid code generation with secrets which are lowercase or space-separated</PackageReleaseNotes>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">