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

[REFACTOR] Remove DotNetZip, replace with SharpZipLib; fixes #349 #353

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use SharpZipLib and implement AES 256 encryption
  • Loading branch information
Alexander van Delft committed Oct 23, 2024
commit 8b759fac8a7a2c222e0ce0c1366f9d0148d48008
5 changes: 3 additions & 2 deletions CDP4Common/CDP4Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Common Community Edition</Title>
<VersionPrefix>27.3.5</VersionPrefix>
<VersionPrefix>27.4.0</VersionPrefix>
<Description>CDP4 Common Class Library that contains DTOs, POCOs</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[Fix] Iteration.QueryUnreferencedElements in case topelement is not set
[ADD] SharpZipLibUtils
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand All @@ -45,6 +45,7 @@

<ItemGroup>
<PackageReference Include="NLog" Version="5.3.4" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
</ItemGroup>
Expand Down
99 changes: 99 additions & 0 deletions CDP4Common/Encryption/SharpZipLibUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="SharpZipLibHelper.cs" company="Starion Group S.A.">
// Copyright (c) 2015-2024 Starion Group S.A.
//
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar
//
// This file is part of CDP4-COMET SDK Community Edition
//
// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// </copyright>
// -------------------------------------------------------------------------------------------------------------------------------

namespace CDP4Common.Encryption
{
using System.IO;

using ICSharpCode.SharpZipLib.Zip;

/// <summary>
/// A class containing Helper Methods for working with SharpZipLib and creating AES 256 encrypted zip files
/// </summary>
public static class SharpZipLibUtils
{
/// <summary>
/// Create a <see cref="ZipOutputStream"/> to create a AES 256 encrypted zip file
/// </summary>
/// <param name="inputStream">The input <see cref="Stream"/> to write to</param>
/// <param name="password">The password to be used to protect the data</param>
/// <returns>The created <see cref="ZipOutputStream"/></returns>
public static ZipOutputStream CreateZipOutputStream(Stream inputStream, string password)
{
var zipStream = new ZipOutputStream(inputStream);
zipStream.Password = password;
zipStream.IsStreamOwner = true; // underlying streams will be forcibly closed

return zipStream;
}

/// <summary>
/// Add a <see cref="ZipEntry"/> and add it to a <see cref="ZipOutputStream"/>
/// </summary>
/// <param name="zipOutputStream">The <see cref="ZipOutputStream"/></param>
/// <param name="stream">The input <see cref="Stream"/> from which to create the <see cref="ZipEntry"/></param>
/// <param name="name">The name of the entry, including (sub)folder information</param>
public static void AddEntryFromStream(ZipOutputStream zipOutputStream, Stream stream, string name)
{
if (stream.Length == 0)
{
return;
}

var entry = new ZipEntry(name)
{
AESKeySize = 256, // Set AES encryption to 256 bits for each individual entry
};

zipOutputStream.PutNextEntry(entry);
stream.Flush();
stream.Position = 0;
stream.CopyTo(zipOutputStream);
zipOutputStream.CloseEntry();
}

/// <summary>
/// Add a file as a <see cref="ZipEntry"/> to an existing <see cref="ZipOutputStream"/>
/// </summary>
/// <param name="zipOutputStream">The <see cref="ZipOutputStream"/></param>
/// <param name="extraFile">The location of the file to add</param>
/// <param name="entryLocation">The location (fullname) of the file to create in the <see cref="ZipOutputStream"/>, including (sub)folder information</param>
public static void AddEntryFromFile(ZipOutputStream zipOutputStream, string extraFile, string entryLocation)
{
var entry = new ZipEntry(entryLocation)
{
AESKeySize = 256, // Set AES encryption to 256 bits
};

zipOutputStream.PutNextEntry(entry);

using (var fileStream = File.OpenRead(extraFile))
{
fileStream.CopyTo(zipOutputStream);
}

zipOutputStream.CloseEntry();
}
}
}
2 changes: 1 addition & 1 deletion CDP4Dal/CDP4Dal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4Dal Community Edition</Title>
<VersionPrefix>27.3.5</VersionPrefix>
<VersionPrefix>27.4.0</VersionPrefix>
<Description>CDP4 Data Access Layer library, a consumer of an ECSS-E-TM-10-25 Annex C API</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed</Authors>
Expand Down
2 changes: 1 addition & 1 deletion CDP4DalCommon/CDP4DalCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Company>Starion Group S.A.</Company>
<Language>latest</Language>
<Title>CDP4DalCommon Community Edition</Title>
<VersionPrefix>27.3.5</VersionPrefix>
<VersionPrefix>27.4.0</VersionPrefix>
<Description>CDP4 Common Class Library that contains common types for any CDP4 server and the CDP4Dal</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Alex, Alexander, Nathanael, Antoine, Omar, Jaime</Authors>
Expand Down
4 changes: 2 additions & 2 deletions CDP4JsonFileDal/CDP4JsonFileDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net48;netstandard2.0</TargetFrameworks>
<Company>Starion Group S.A.</Company>
<Title>CDP4JsonFileDal Community Edition</Title>
<VersionPrefix>27.3.6</VersionPrefix>
<VersionPrefix>27.4.0</VersionPrefix>
<Description>CDP4 Json File Dal Plugin</Description>
<Copyright>Copyright © Starion Group S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael</Authors>
Expand All @@ -20,7 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
- Remove DotNetZip and start using System.IO.Compression
- Remove DotNetZip and use SharpZipLib
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
Loading
Loading