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:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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'">
|
||||
|
||||
Reference in New Issue
Block a user