Skip to content

GAM TOTP EO migration to Github #1058

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions dotnet/DotNetStandardClasses.sln
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LogTest", "test\benchmarks\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AccessTokenController_Test", "test\NativeAccessControllerTest\AccessTokenController_Test.csproj", "{A5589382-DB6F-4450-AE2B-6C6AA1643EF1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gam", "gam", "{2A5D5796-C1AD-4611-ABBD-496431ADC705}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{69A80913-7924-421B-8378-6367E90F4A70}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNet", "DotNet", "{8CD470A6-D8A9-4BE8-95AB-9A2A0B0861B8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNetFramework", "DotNetFramework", "{708A8C53-73A2-4D03-BC21-19EA58ACFA8B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GamTotp", "src\extensions\gam\src\DotNetFramework\GamTotp\GamTotp.csproj", "{463C9F3B-ED87-43B0-A09A-E46B50BBEE6E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GamTotpNet", "src\extensions\gam\src\DotNet\GamTotpNet\GamTotpNet.csproj", "{AA8BA0B9-E6D2-427B-BF08-7368E5602DBE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -641,6 +653,14 @@ Global
{A5589382-DB6F-4450-AE2B-6C6AA1643EF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5589382-DB6F-4450-AE2B-6C6AA1643EF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5589382-DB6F-4450-AE2B-6C6AA1643EF1}.Release|Any CPU.Build.0 = Release|Any CPU
{463C9F3B-ED87-43B0-A09A-E46B50BBEE6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{463C9F3B-ED87-43B0-A09A-E46B50BBEE6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{463C9F3B-ED87-43B0-A09A-E46B50BBEE6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{463C9F3B-ED87-43B0-A09A-E46B50BBEE6E}.Release|Any CPU.Build.0 = Release|Any CPU
{AA8BA0B9-E6D2-427B-BF08-7368E5602DBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA8BA0B9-E6D2-427B-BF08-7368E5602DBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA8BA0B9-E6D2-427B-BF08-7368E5602DBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA8BA0B9-E6D2-427B-BF08-7368E5602DBE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -767,6 +787,12 @@ Global
{46DAAFD1-FAF5-4904-8EC5-406BE04E5538} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{A1DBDCE0-4F09-445F-A202-9B260CDD46CF} = {46DAAFD1-FAF5-4904-8EC5-406BE04E5538}
{A5589382-DB6F-4450-AE2B-6C6AA1643EF1} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{2A5D5796-C1AD-4611-ABBD-496431ADC705} = {C6AFB6A3-FF0B-4970-B1F1-10BCD3D932B2}
{69A80913-7924-421B-8378-6367E90F4A70} = {2A5D5796-C1AD-4611-ABBD-496431ADC705}
{8CD470A6-D8A9-4BE8-95AB-9A2A0B0861B8} = {69A80913-7924-421B-8378-6367E90F4A70}
{708A8C53-73A2-4D03-BC21-19EA58ACFA8B} = {69A80913-7924-421B-8378-6367E90F4A70}
{463C9F3B-ED87-43B0-A09A-E46B50BBEE6E} = {708A8C53-73A2-4D03-BC21-19EA58ACFA8B}
{AA8BA0B9-E6D2-427B-BF08-7368E5602DBE} = {8CD470A6-D8A9-4BE8-95AB-9A2A0B0861B8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C}
Expand Down
28 changes: 28 additions & 0 deletions dotnet/src/extensions/gam/src/DotNet/GamTotpNet/GamTotpNet.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<AssemblyName>GamTotpNetImpl</AssemblyName>
<Version>17.4.0</Version>
<NoWarn>CA1031, CA1801, SYSLIB0027</NoWarn>
<PackageId>Gam.Totp.Net</PackageId>
</PropertyGroup>

<PropertyGroup>
<DefineConstants>NETCORE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\DotNetFramework\GamTotp\TOTPAuthenticator.cs" Link="TOTPAuthenticator.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="GoogleAuthenticator" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\dotnetcore\GxClasses\GxClasses.csproj" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<AssemblyName>GamTotpImpl</AssemblyName>
<NoWarn>CA1031, CA1801</NoWarn>
<PackageId>Gam.Totp</PackageId>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GoogleAuthenticator" Version="3.2.0" />
<PackageReference Include="StrongNamer" Version="0.2.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\dotnetframework\GxClasses\GxClasses.csproj" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Security;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AllowPartiallyTrustedCallers]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using Google.Authenticator;
using System.Security.Cryptography;
using System.Security;
using log4net;

namespace GamTotp
{
public class TOTPAuthenticator
{
private static readonly ILog logger = LogManager.GetLogger(typeof(TOTPAuthenticator));

[SecuritySafeCritical]
public static string GenerateKey(int length)
{
logger.Debug("GenerateKey");
byte[] randomBytes = new byte[length];
using (var rng = RandomNumberGenerator.Create()) {
rng.GetBytes(randomBytes);
string str = Base32Encoding.ToString(randomBytes).TrimEnd('=');
return str.Remove(length);
}
}

[SecuritySafeCritical]
public static string GenerateQRData(string accountName, string secretKey, string appName, string algorithm, int digits, int period)
{
logger.Debug("GenerateQRData");
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
SetupCode setupInfo = tfa.GenerateSetupCode(appName, accountName, secretKey, true, 6);

return setupInfo.QrCodeSetupImageUrl;
}

[SecuritySafeCritical]
public static bool VerifyTOTPCode(string secretKey, string code, string algorithm, int digits, int period)
{
logger.Debug("VerifyTOTPCode");
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
return tfa.ValidateTwoFactorPIN(secretKey, code, TimeSpan.FromSeconds(period), true);
}
}
}