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

GAM Cryptography EO migration from SVN to GamUtils EO on Github #1055

Open
wants to merge 16 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
49 changes: 49 additions & 0 deletions dotnet/DotNetStandardClasses.sln
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,28 @@ 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", "{BAD7F078-C67E-484A-AF74-EC29F163F1F7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7465132B-47BD-44D1-8193-483465FD94F4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{035C3DAF-553E-4E64-BA9E-113F5C80FD97}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNet", "DotNet", "{56429994-8A51-48AB-8105-737B77840D18}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNetFramework", "DotNetFramework", "{B3B988A2-AFF1-41E6-82DC-578D332A5CB8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GamUtils", "src\extensions\gam\src\DotNetFramework\GamUtils\GamUtils.csproj", "{34FE57F2-E45F-4F9B-AFEE-60D9CA8373A7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNet", "DotNet", "{1942B0FE-49BD-4EC4-9788-F19FDD921E69}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNetFramework", "DotNetFramework", "{B33F3709-5EA0-4FE8-9E3A-50D3046817D6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GamTest", "src\extensions\gam\test\DotNetFramework\GamTest\GamTest.csproj", "{52B67EA3-B17D-4002-8EC3-0D5DDB62988B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GamUtilsNet", "src\extensions\gam\src\DotNet\GamUtilsNet\GamUtilsNet.csproj", "{AA93273B-2E0B-4CD3-A921-A462B214F424}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GamTestNet", "src\extensions\gam\test\DotNet\GamTestNet\GamTestNet.csproj", "{D46D0666-AF65-4875-954C-82AB2240B17D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -641,6 +663,22 @@ 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
{34FE57F2-E45F-4F9B-AFEE-60D9CA8373A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34FE57F2-E45F-4F9B-AFEE-60D9CA8373A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34FE57F2-E45F-4F9B-AFEE-60D9CA8373A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34FE57F2-E45F-4F9B-AFEE-60D9CA8373A7}.Release|Any CPU.Build.0 = Release|Any CPU
{52B67EA3-B17D-4002-8EC3-0D5DDB62988B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52B67EA3-B17D-4002-8EC3-0D5DDB62988B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52B67EA3-B17D-4002-8EC3-0D5DDB62988B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52B67EA3-B17D-4002-8EC3-0D5DDB62988B}.Release|Any CPU.Build.0 = Release|Any CPU
{AA93273B-2E0B-4CD3-A921-A462B214F424}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA93273B-2E0B-4CD3-A921-A462B214F424}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA93273B-2E0B-4CD3-A921-A462B214F424}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA93273B-2E0B-4CD3-A921-A462B214F424}.Release|Any CPU.Build.0 = Release|Any CPU
{D46D0666-AF65-4875-954C-82AB2240B17D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D46D0666-AF65-4875-954C-82AB2240B17D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D46D0666-AF65-4875-954C-82AB2240B17D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D46D0666-AF65-4875-954C-82AB2240B17D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -767,6 +805,17 @@ 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}
{BAD7F078-C67E-484A-AF74-EC29F163F1F7} = {C6AFB6A3-FF0B-4970-B1F1-10BCD3D932B2}
{7465132B-47BD-44D1-8193-483465FD94F4} = {BAD7F078-C67E-484A-AF74-EC29F163F1F7}
{035C3DAF-553E-4E64-BA9E-113F5C80FD97} = {BAD7F078-C67E-484A-AF74-EC29F163F1F7}
{56429994-8A51-48AB-8105-737B77840D18} = {7465132B-47BD-44D1-8193-483465FD94F4}
{B3B988A2-AFF1-41E6-82DC-578D332A5CB8} = {7465132B-47BD-44D1-8193-483465FD94F4}
{34FE57F2-E45F-4F9B-AFEE-60D9CA8373A7} = {B3B988A2-AFF1-41E6-82DC-578D332A5CB8}
{1942B0FE-49BD-4EC4-9788-F19FDD921E69} = {035C3DAF-553E-4E64-BA9E-113F5C80FD97}
{B33F3709-5EA0-4FE8-9E3A-50D3046817D6} = {035C3DAF-553E-4E64-BA9E-113F5C80FD97}
{52B67EA3-B17D-4002-8EC3-0D5DDB62988B} = {B33F3709-5EA0-4FE8-9E3A-50D3046817D6}
{AA93273B-2E0B-4CD3-A921-A462B214F424} = {56429994-8A51-48AB-8105-737B77840D18}
{D46D0666-AF65-4875-954C-82AB2240B17D} = {1942B0FE-49BD-4EC4-9788-F19FDD921E69}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="6.35.0" />
<PackageReference Include="Microsoft.IdentityModel.Logging" Version="6.35.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.35.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="8.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="jose-jwt" Version="5.0.0" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="4.7.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net47</TargetFramework>
<RootNamespace>GeneXusCryptography</RootNamespace>
Expand All @@ -7,7 +7,7 @@
<PackageId>GeneXus.SecurityApi.Cryptography</PackageId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SecurityAPICommons\SecurityAPICommons.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<None Include="App.Release.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="6.34.0" />
<PackageReference Include="Microsoft.IdentityModel.Logging" Version="6.34.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.34.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageId>GeneXus.SecurityApi.XmlSignature</PackageId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SecurityAPICommons\SecurityAPICommons.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="jose-jwt" Version="5.0.0" />
<PackageReference Include="StrongNamer" Version="0.2.5" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="4.7.0" />
Expand Down
Binary file added dotnet/src/extensions/gam/gamkey.snk
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

<ItemGroup>
<Compile Include="..\..\DotNetFramework\GamUtils\GamUtilsEO.cs" Link="GamUtilsEO.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\Cryprography\Encryption.cs" Link="Utils\Cryptography\Encryption.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\Cryprography\Hash.cs" Link="Utils\Cryptography\Hash.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\DynamicCall.cs" Link="Utils\DynamicCall.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\Json\Jwk.cs" Link="Utils\Json\Jwk.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\Json\Jwt.cs" Link="Utils\Json\Jwt.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\Json\UnixTimestamp.cs" Link="Utils\Json\UnixTimestamp.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\Keys\PublicKeyExt.cs" Link="Utils\Keys\PublicKeyExt.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\Keys\PrivateKeyExt.cs" Link="Utils\Keys\PrivateKeyExt.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\Random.cs" Link="Utils\Random.cs" />
<Compile Include="..\..\DotNetFramework\GamUtils\Utils\Encoding.cs" Link="Utils\Encoding.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="jose-jwt" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="4.7.0" />
</ItemGroup>

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

<ItemGroup>
<Folder Include="Utils\Cryptography\" />
<Folder Include="Utils\Keys\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net47</TargetFramework>
<AssemblyName>GamUtilsImpl</AssemblyName>
<NoWarn>CA1031, CA1801</NoWarn>
<PackageId>Gam.Utils</PackageId>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\gamkey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="jose-jwt" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="StrongNamer" Version="0.2.5" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="4.7.0" />
</ItemGroup>

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


</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Security;
using GamUtils.Utils;
using GamUtils.Utils.Cryprography;
using GamUtils.Utils.Json;

namespace GamUtils
{
[SecuritySafeCritical]
public class GamUtilsEO
{
/********EXTERNAL OBJECT PUBLIC METHODS - BEGIN ********/

//**HASH**//
[SecuritySafeCritical]
public static string Sha512(string plainText)
{
return HashUtil.Hashing(plainText, Hash.SHA512);
}

[SecuritySafeCritical]
public static string Sha256(string plainText)
{
return HashUtil.Hashing(plainText, Hash.SHA256);
}

//**ENCRYPTION**//

[SecuritySafeCritical]
public static string AesGcm(string input, string key, string nonce, int macSize, bool toEncrypt)
{
return Encryption.AesGcm(input, key, nonce, macSize, toEncrypt);
}

//**RANDOM**//
[SecuritySafeCritical]
public static string RandomAlphanumeric(int length)
{
return Utils.Random.Alphanumeric(length);
}

[SecuritySafeCritical]
public static string RandomNumeric(int length)
{
return Utils.Random.Numeric(length);
}

[SecuritySafeCritical]
public static string RandomHexaBits(int bits)
{
return Utils.Random.HexaBits(bits);
}

//**JWK**//
[SecuritySafeCritical]
public static string GenerateKeyPair() { return Jwk.GenerateKeyPair(); }

[SecuritySafeCritical]
public static string GetPublicJwk(string jwkString) { return Jwk.GetPublic(jwkString); }

//**JWT**//
[SecuritySafeCritical]
public static bool VerifyJwt(string path, string alias, string password, string token) { return Jwt.Verify(path, alias, password, token); }

[SecuritySafeCritical]
public static string CreateJwt(string path, string alias, string password, string payload, string header) { return Jwt.Create(path, alias, password, payload, header); }

[SecuritySafeCritical]
public static long CreateUnixTimestamp(DateTime date) { return UnixTimestamp.Create(date); }

[SecuritySafeCritical]
public static string GetJwtHeader(string token) { return Jwt.GetHeader(token); }

[SecuritySafeCritical]
public static string GetJwtPayload(string token) { return Jwt.GetPayload(token); }

//**ENCODING**//
public static string Base64ToBase64Url(string base64) { return Encoding.B64ToB64Url(base64); }
}
}
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,46 @@
using System;
using System.Security;
using System.Text;
using log4net;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Utilities.Encoders;

namespace GamUtils.Utils.Cryprography
{
[SecuritySafeCritical]
internal class Encryption
{

private static readonly ILog logger = LogManager.GetLogger(typeof(Encryption));

[SecuritySafeCritical]
public static string AesGcm(string input, string key, string nonce, int macSize, bool toEncrypt)
{
return toEncrypt ? Base64.ToBase64String(Internal_AesGcm(System.Text.Encoding.UTF8.GetBytes(input), key, nonce, macSize, toEncrypt)) : System.Text.Encoding.UTF8.GetString(Internal_AesGcm(Base64.Decode(input), key, nonce, macSize, toEncrypt));
}

[SecuritySafeCritical]
private static byte[] Internal_AesGcm(byte[] inputBytes, string key, string nonce, int macSize, bool toEncrypt)
{
logger.Debug("Internal_AesGcm");

IAeadBlockCipher cipher = new GcmBlockCipher(new AesEngine());
AeadParameters AEADparams = new AeadParameters(new KeyParameter(Hex.Decode(key)), macSize, Hex.Decode(nonce));
try
{
cipher.Init(toEncrypt, AEADparams);
byte[] outputBytes = new byte[cipher.GetOutputSize(inputBytes.Length)];
int length = cipher.ProcessBytes(inputBytes, 0, inputBytes.Length, outputBytes, 0);
cipher.DoFinal(outputBytes, length);
return outputBytes;
}
catch (Exception e)
{
logger.Error("Internal_AesGcm", e);
return null;
}
}
}
}
Loading
Loading