diff --git a/FitConnect.sln b/FitConnect.sln index a5105f7cea13fc3173f1146c0a3262e495c5acee..a835c7cbdd499f2342cd158ffa4b3472e54781ba 100644 --- a/FitConnect.sln +++ b/FitConnect.sln @@ -24,6 +24,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValidationTests", "Tests\Va EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyManagement", "KeyManagement\KeyManagement.csproj", "{D872CF15-8E00-4DD5-AB22-3DEA783F251F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EncryptionConsoleRunner", "Tests\EncryptionConsoleRunner\EncryptionConsoleRunner.csproj", "{4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -74,6 +76,10 @@ Global {D872CF15-8E00-4DD5-AB22-3DEA783F251F}.Debug|Any CPU.Build.0 = Debug|Any CPU {D872CF15-8E00-4DD5-AB22-3DEA783F251F}.Release|Any CPU.ActiveCfg = Release|Any CPU {D872CF15-8E00-4DD5-AB22-3DEA783F251F}.Release|Any CPU.Build.0 = Release|Any CPU + {4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C58A2CD-9408-43EA-823A-64FE7BDFBFD3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {27115A99-2AE8-42BC-9495-BE2DCEDDF1E8} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5} @@ -84,5 +90,6 @@ Global {8428631D-E396-4685-BE34-5E6C3307EE97} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5} {29874608-52A5-49B0-A806-7F076750FE02} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5} {DDEFDA59-FD75-4F25-9BA2-8DAE22B4A0B0} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5} + {4C58A2CD-9408-43EA-823A-64FE7BDFBFD3} = {180029B5-8DD3-4594-B34E-6C07AF1C52C5} EndGlobalSection EndGlobal diff --git a/Tests/EncryptionConsoleRunner/Dockerfile b/Tests/EncryptionConsoleRunner/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..5de95e8b1987e5182cecb8bf6c8800f83ba5fd49 --- /dev/null +++ b/Tests/EncryptionConsoleRunner/Dockerfile @@ -0,0 +1,20 @@ +FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base +WORKDIR /app + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["Tests/EncryptionConsoleRunner/EncryptionConsoleRunner.csproj", "Tests/EncryptionConsoleRunner/"] +RUN dotnet restore "Tests/EncryptionConsoleRunner/EncryptionConsoleRunner.csproj" +COPY . . +WORKDIR "/src/Tests/EncryptionConsoleRunner" +RUN dotnet build "EncryptionConsoleRunner.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "EncryptionConsoleRunner.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "EncryptionConsoleRunner.dll"] diff --git a/Tests/EncryptionConsoleRunner/EncryptionConsoleRunner.csproj b/Tests/EncryptionConsoleRunner/EncryptionConsoleRunner.csproj new file mode 100644 index 0000000000000000000000000000000000000000..dd639224b4b1ceb9e19efc5115080f4eef332df6 --- /dev/null +++ b/Tests/EncryptionConsoleRunner/EncryptionConsoleRunner.csproj @@ -0,0 +1,23 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> + </PropertyGroup> + + <ItemGroup> + <Content Include="..\..\.dockerignore"> + <Link>.dockerignore</Link> + </Content> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\..\FitConnect\FitConnect.csproj" /> + <ProjectReference Include="..\..\JwkGenerator\JwkGenerator.csproj" /> + <ProjectReference Include="..\..\KeyManagement\KeyManagement.csproj" /> + </ItemGroup> + +</Project> diff --git a/Tests/EncryptionConsoleRunner/Program.cs b/Tests/EncryptionConsoleRunner/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..3ee7c5a30e6b08c7467f87d0d74d2729f42f2a2c --- /dev/null +++ b/Tests/EncryptionConsoleRunner/Program.cs @@ -0,0 +1,42 @@ +// See https://aka.ms/new-console-template for more information + +using System.ComponentModel; +using System.Security.Cryptography; +using FitConnect.Encryption; +using FitConnect.KeyManagement; + +Console.WriteLine("Hello, World!"); + +var keySet = new FitConnect.KeyManagement.Generator().CreateKeys(); +EncryptLargeFiles_ShouldPass(750, keySet.publicKey.ToJson()); + + +void EncryptLargeFiles_ShouldPass(int fileSizeInMb, string publicKey) { + // Arrange + var sourceFile = RandomNumberGenerator.GetBytes(1024 * 1024 * fileSizeInMb); + Console.WriteLine($"Encrypting {fileSizeInMb} MB file"); + var encryption = new FitEncryption(publicKey, null); + + // Act + var encryptedFile = encryption.Encrypt(sourceFile); + + // Assert + +} + + +void FindMaxFileSizeForEncryption(string publicKey) { + for (var start = 750; start < 800; start++) { + Console.Write($"Trying to encrypt {start} MB file"); + try { + EncryptLargeFiles_ShouldPass(start, publicKey); + Console.WriteLine("...success"); + } + catch (Exception e) { + Console.WriteLine("...failed"); + Console.WriteLine(e); + Console.WriteLine($"Max file size for encryption is {start - 1} MB"); + break; + } + } +}