Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ dotnet/dotnetframework/GeneXusFtps/obj/
dotnet/dotnetframework/GeneXusFtps/bin/
dotnet/dotnetframework/GeneXusFtps/packages.config
dotnet/dotnetcore/GeneXusFtpsNetCore/obj/
dotnet/resources/key.snk
9 changes: 8 additions & 1 deletion SecurityAPIParent.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dotnetframework", "dotnetfr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecurityAPITest", "test\dotnetframework\SecurityAPITest\SecurityAPITest.csproj", "{9100025A-68E0-4618-B83C-4D626CB89DBB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecurityAPITestNetCore", "test\dotnetcore\SecurityAPITestNetCore\SecurityAPITestNetCore.csproj", "{44B8B2B6-0842-4018-A547-EF33920EFC8E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecurityAPITestNetCore", "test\dotnetcore\SecurityAPITestNetCore\SecurityAPITestNetCore.csproj", "{44B8B2B6-0842-4018-A547-EF33920EFC8E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "resources", "resources", "{88EB1BC4-0D68-4906-AA36-E1EA1F6AFD35}"
ProjectSection(SolutionItems) = preProject
dotnet\resources\key.snk = dotnet\resources\key.snk
dotnet\resources\Neon.SSH.NET.dll = dotnet\resources\Neon.SSH.NET.dll
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -128,6 +134,7 @@ Global
{7F5F1DDC-09BE-4567-8CD4-41387AD91BEE} = {750343D3-EAA6-433E-A099-71BC6851EA71}
{9100025A-68E0-4618-B83C-4D626CB89DBB} = {7F5F1DDC-09BE-4567-8CD4-41387AD91BEE}
{44B8B2B6-0842-4018-A547-EF33920EFC8E} = {89FFECB3-7A69-41F8-88C7-F05193E5CDF4}
{88EB1BC4-0D68-4906-AA36-E1EA1F6AFD35} = {5CB1725B-3FA5-49B1-A1F8-41EFCACA3CF1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AEB1693D-906F-402A-AD66-A1A9AE2ABBE2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\resources\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.6.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\..\..\packages\BouncyCastle.1.8.6.1\lib\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -85,6 +88,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="..\..\resources\key.snk">
<Link>key.snk</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
Expand Down
12 changes: 9 additions & 3 deletions dotnet/dotnetframework/GeneXusFtps/GeneXusFtps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\resources\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentFTP, Version=31.3.2.0, Culture=neutral, PublicKeyToken=f4af092b1d8df44f, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\FluentFTP.31.3.2\lib\net45\FluentFTP.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
Expand Down Expand Up @@ -62,6 +65,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="..\..\resources\key.snk">
<Link>key.snk</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
27 changes: 9 additions & 18 deletions dotnet/dotnetframework/GeneXusJWT/GeneXusJWT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,18 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\resources\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<AppConfig>App.$(Configuration).config</AppConfig>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.6.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\..\..\packages\BouncyCastle.1.8.6.1\lib\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.JsonWebTokens, Version=6.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.IdentityModel.JsonWebTokens.6.5.1\lib\net45\Microsoft.IdentityModel.JsonWebTokens.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Logging, Version=6.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Logging.6.5.1\lib\net45\Microsoft.IdentityModel.Logging.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Tokens, Version=6.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Tokens.6.5.1\lib\net45\Microsoft.IdentityModel.Tokens.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=6.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.IdentityModel.Tokens.Jwt.6.5.1\lib\net45\System.IdentityModel.Tokens.Jwt.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -84,6 +72,9 @@
<Compile Include="Utils\RevocationList.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\resources\key.snk">
<Link>key.snk</Link>
</None>
<None Include="app.config" />
<None Include="App.Debug.config" />
<None Include="packages.config" />
Expand Down
13 changes: 11 additions & 2 deletions dotnet/dotnetframework/GeneXusSftp/GeneXusSftp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\resources\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -32,8 +38,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Neon.SSH.NET, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Neon.SSH.NET.1.0.4\lib\netstandard2.0\Neon.SSH.NET.dll</HintPath>
<Reference Include="Neon.SSH.NET">
<HintPath>..\..\resources\Neon.SSH.NET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -54,6 +60,9 @@
<Compile Include="Utils\KnownHostStore.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\resources\key.snk">
<Link>key.snk</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\resources\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
Expand All @@ -32,9 +38,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.6.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Portable.BouncyCastle.1.8.6.7\lib\net40\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Security" />
Expand All @@ -61,6 +64,9 @@
<Compile Include="Utils\XmlSignatureWrapper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\resources\key.snk">
<Link>key.snk</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
22 changes: 18 additions & 4 deletions dotnet/dotnetframework/SecurityAPICommons/Config/Global.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Runtime.CompilerServices;


[assembly: InternalsVisibleTo("SecurityAPITestNetCore")]
[assembly: InternalsVisibleTo("SecurityAPITest")]

namespace SecurityAPICommons.Config
{

internal static class Global
public static class Global
{
private static string global_encoding = "UTF_8";
public static string GLOBAL_ENCODING
Expand All @@ -24,7 +23,22 @@ public static string GLOBAL_ENCODING
global_encoding = value;
}
}

private static string global_keyContainerName = "";
public static string GLOBAL_KEY_COONTAINER_NAME
{
get
{
if (global_keyContainerName == null)
{
return "UTF_8";
}
return global_keyContainerName;
}
set
{
global_keyContainerName = value;
}
}


}
Expand Down
65 changes: 53 additions & 12 deletions dotnet/dotnetframework/SecurityAPICommons/Keys/PrivateKeyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using SecurityAPICommons.Commons;
using SecurityAPICommons.Utils;
using Org.BouncyCastle.Utilities.Encoders;
using System.Security.AccessControl;

namespace SecurityAPICommons.Keys
{
Expand Down Expand Up @@ -153,15 +154,35 @@ public AsymmetricAlgorithm getPrivateKeyForXML()
byte[] serializedPrivateBytes = this.privateKeyInfo.ToAsn1Object().GetDerEncoded();
string serializedPrivate = Convert.ToBase64String(serializedPrivateBytes);
RsaPrivateCrtKeyParameters privateKey = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(serializedPrivate));
#if NETCORE
return DotNetUtilities.ToRSA(privateKey);
#else


/****System.Security.Cryptography.CryptographicException: The system cannot find the file specified.****/
/****HACK****/
//https://social.msdn.microsoft.com/Forums/vstudio/en-US/7ea48fd0-8d6b-43ed-b272-1a0249ae490f/systemsecuritycryptographycryptographicexception-the-system-cannot-find-the-file-specified?forum=clr#37d4d83d-0eb3-497a-af31-030f5278781a
CspParameters cspParameters = new CspParameters();
cspParameters.Flags = CspProviderFlags.UseMachineKeyStore;
cspParameters.KeyContainerName = "MyKeyContainerName";
return DotNetUtilities.ToRSA(privateKey, cspParameters);
if (SecurityUtils.compareStrings(Config.Global.GLOBAL_KEY_COONTAINER_NAME, ""))
{
string uid = Guid.NewGuid().ToString();
cspParameters.KeyContainerName = uid;
Config.Global.GLOBAL_KEY_COONTAINER_NAME = uid;
System.Security.Principal.SecurityIdentifier userId = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WindowsIdentity.GetCurrent().User.ToString());
CryptoKeyAccessRule rule = new CryptoKeyAccessRule(userId, CryptoKeyRights.FullControl, AccessControlType.Allow);
cspParameters.CryptoKeySecurity = new CryptoKeySecurity();
cspParameters.CryptoKeySecurity.SetAccessRule(rule);
}
else
{
cspParameters.KeyContainerName = Config.Global.GLOBAL_KEY_COONTAINER_NAME;

}
/****System.Security.Cryptography.CryptographicException: The system cannot find the file specified.****/
/****HACK****/
return DotNetUtilities.ToRSA(privateKey, cspParameters);
#endif


}
Expand Down Expand Up @@ -524,17 +545,37 @@ public AsymmetricAlgorithm getPrivateKeyForJWT()
byte[] serializedPrivateBytes = this.privateKeyInfo.ToAsn1Object().GetDerEncoded();
string serializedPrivate = Convert.ToBase64String(serializedPrivateBytes);
RsaPrivateCrtKeyParameters privateKey = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(serializedPrivate));
/****System.Security.Cryptography.CryptographicException: The system cannot find the file specified.****/
/****HACK****/
//https://social.msdn.microsoft.com/Forums/vstudio/en-US/7ea48fd0-8d6b-43ed-b272-1a0249ae490f/systemsecuritycryptographycryptographicexception-the-system-cannot-find-the-file-specified?forum=clr#37d4d83d-0eb3-497a-af31-030f5278781a
CspParameters cspParameters = new CspParameters();
cspParameters.Flags = CspProviderFlags.UseMachineKeyStore;
cspParameters.KeyContainerName = "MyKeyContainerName";
alg = DotNetUtilities.ToRSA(privateKey, cspParameters);
/****System.Security.Cryptography.CryptographicException: The system cannot find the file specified.****/
/****HACK****/
#if NETCORE
alg = DotNetUtilities.ToRSA(privateKey);
#else


/****System.Security.Cryptography.CryptographicException: The system cannot find the file specified.****/
/****HACK****/
//https://social.msdn.microsoft.com/Forums/vstudio/en-US/7ea48fd0-8d6b-43ed-b272-1a0249ae490f/systemsecuritycryptographycryptographicexception-the-system-cannot-find-the-file-specified?forum=clr#37d4d83d-0eb3-497a-af31-030f5278781a
CspParameters cspParameters = new CspParameters();
cspParameters.Flags = CspProviderFlags.UseMachineKeyStore;
if (SecurityUtils.compareStrings(Config.Global.GLOBAL_KEY_COONTAINER_NAME, ""))
{
string uid = Guid.NewGuid().ToString();
cspParameters.KeyContainerName = uid;
Config.Global.GLOBAL_KEY_COONTAINER_NAME = uid;
System.Security.Principal.SecurityIdentifier userId = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WindowsIdentity.GetCurrent().User.ToString());
CryptoKeyAccessRule rule = new CryptoKeyAccessRule(userId, CryptoKeyRights.FullControl, AccessControlType.Allow);
cspParameters.CryptoKeySecurity = new CryptoKeySecurity();
cspParameters.CryptoKeySecurity.SetAccessRule(rule);
}
else
{
cspParameters.KeyContainerName = Config.Global.GLOBAL_KEY_COONTAINER_NAME;

}
else if (SecurityUtils.compareStrings("ECDSA", algorithm))
/****System.Security.Cryptography.CryptographicException: The system cannot find the file specified.****/
/****HACK****/
alg = DotNetUtilities.ToRSA(privateKey, cspParameters);
#endif
}
else if (SecurityUtils.compareStrings("ECDSA", algorithm))
{
string b64Encoded = this.ToBase64();
byte[] privKeyBytes8 = Convert.FromBase64String(b64Encoded);//Encoding.UTF8.GetBytes(privKeyEcc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\resources\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.6.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\..\..\packages\BouncyCastle.1.8.6.1\lib\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
Expand Down Expand Up @@ -73,6 +76,9 @@
<Compile Include="Utils\SecurityUtils.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\resources\key.snk">
<Link>key.snk</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Binary file added dotnet/resources/Neon.SSH.NET.dll
Binary file not shown.