Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed to use EscapeDataString #120

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Google.Authenticator.Tests/QRCodeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace Google.Authenticator.Tests
public class QRCodeTest
{
[Theory]
[InlineData("issuer", "otpauth://totp/issuer:a@b.com?secret=ONSWG4TFOQ&issuer=issuer")]
[InlineData("Foo & Bar", "otpauth://totp/Foo%20%26%20Bar:a@b.com?secret=ONSWG4TFOQ&issuer=Foo%20%26%20Bar")]
[InlineData("个", "otpauth://totp/%E4%B8%AA:a@b.com?secret=ONSWG4TFOQ&issuer=%E4%B8%AA")]
[InlineData("issuer", "otpauth://totp/issuer:a%40b.com?secret=ONSWG4TFOQ&issuer=issuer")]
[InlineData("Foo & Bar", "otpauth://totp/Foo%20%26%20Bar:a%40b.com?secret=ONSWG4TFOQ&issuer=Foo%20%26%20Bar")]
[InlineData("个", "otpauth://totp/%E4%B8%AA:a%40b.com?secret=ONSWG4TFOQ&issuer=%E4%B8%AA")]
public void CanGenerateQRCode(string issuer, string expectedUrl)
{
var subject = new TwoFactorAuthenticator();
Expand Down
2 changes: 1 addition & 1 deletion Google.Authenticator/Google.Authenticator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Description>Google Authenticator Two-Factor Authentication Library (Not officially affiliated with Google.)</Description>
<Authors>Brandon Potter</Authors>
<Company>Brandon Potter</Company>
<Version>3.0.0-beta1</Version>
<Version>3.0.0-beta2</Version>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/BrandonPotter/GoogleAuthenticator</PackageProjectUrl>
<PackageId>GoogleAuthenticator</PackageId>
Expand Down
7 changes: 1 addition & 6 deletions Google.Authenticator/TwoFactorAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ public SetupCode GenerateSetupCode(string issuer,
throw new NullReferenceException("Account Title is null");
}

// MS wants us to change this to use EscapeDataString - https://docs.microsoft.com/en-us/dotnet/fundamentals/syslib-diagnostics/syslib0013
// But that changes the output. Specifically "[email protected]" becomes "a%40b.com"
// See issue https://github.com/BrandonPotter/GoogleAuthenticator/issues/103
#pragma warning disable SYSLIB0013
accountTitleNoSpaces = RemoveWhitespace(Uri.EscapeUriString(accountTitleNoSpaces));
#pragma warning restore SYSLIB0013
accountTitleNoSpaces = RemoveWhitespace(Uri.EscapeDataString(accountTitleNoSpaces));

var encodedSecretKey = Base32Encoding.ToString(accountSecretKey);

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ bool result = tfa.ValidateTwoFactorPIN(key, txtCode.Text)

## Updates

### 3.0.0-beta
### 3.0.0-beta2
Changed from using `EscapeUriString` to `EscapeDataString` to encode the "account title" as the former is [obsolete in .Net 6](https://docs.microsoft.com/en-us/dotnet/fundamentals/syslib-diagnostics/syslib0013). This changes the value in the generated data string from `[email protected]` to `a%40b.com`. We have tested this with Google Authenticator, Lastpass Authenticator and Microsoft Authenticator. All three of them handle it correctl and all three recognise that it is still the same account so this should be safe in most cases.

### 3.0.0-beta1
- Removed support for legacy .Net Framework. Lowest supported versions are now netstandard2.0 and .Net 4.6.2.
- All use of System.Drawing has been removed. In 2.5, only Net 6.0 avoided System.Drawing.
- Linux installations no longer need to ensure `libgdiplus` is installed as it is no longer used.
Expand Down