From 38a5b9b6c15da2db19576e40ac524f7440b59d66 Mon Sep 17 00:00:00 2001 From: mattosaurus Date: Wed, 29 May 2024 16:32:41 +0100 Subject: [PATCH 1/7] Simplify ChainLiteralOut signatures --- PgpCore/PGP.cs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/PgpCore/PGP.cs b/PgpCore/PGP.cs index 73c8a22..7592d75 100644 --- a/PgpCore/PGP.cs +++ b/PgpCore/PGP.cs @@ -80,7 +80,7 @@ private async Task OutputEncryptedAsync(Stream inputStream, Stream outputStream, using (Stream compressedOut = ChainCompressedOut(encryptedOut)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat)) + using (Stream literalOut = ChainLiteralOut(compressedOut, inputStream, name, oldFormat)) { await WriteOutputAndSignAsync(compressedOut, literalOut, inputStream, signatureGenerator); } @@ -117,7 +117,7 @@ private void OutputEncrypted(Stream inputStream, Stream outputStream, bool withI using (Stream compressedOut = ChainCompressedOut(encryptedOut)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat)) + using (Stream literalOut = ChainLiteralOut(compressedOut, inputStream, name, oldFormat)) { WriteOutputAndSign(compressedOut, literalOut, inputStream, signatureGenerator); } @@ -150,7 +150,7 @@ private async Task OutputSignedAsync(Stream inputStream, Stream outputStream, using (Stream compressedOut = ChainCompressedOut(outputStream)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat)) + using (Stream literalOut = ChainLiteralOut(compressedOut, inputStream, name, oldFormat)) { await WriteOutputAndSignAsync(compressedOut, literalOut, inputStream, signatureGenerator); } @@ -181,7 +181,7 @@ private void OutputSigned(Stream inputStream, Stream outputStream, string name, using (Stream compressedOut = ChainCompressedOut(outputStream)) { PgpSignatureGenerator signatureGenerator = InitSignatureGenerator(compressedOut); - using (Stream literalOut = ChainLiteralStreamOut(compressedOut, inputStream, name, oldFormat)) + using (Stream literalOut = ChainLiteralOut(compressedOut, inputStream, name, oldFormat)) { WriteOutputAndSign(compressedOut, literalOut, inputStream, signatureGenerator); } @@ -390,26 +390,23 @@ private Stream ChainCompressedOut(Stream encryptedOut) private Stream ChainLiteralOut(Stream compressedOut, FileInfo file, string name, bool oldFormat) { PgpLiteralDataGenerator pgpLiteralDataGenerator = new PgpLiteralDataGenerator(oldFormat); - return pgpLiteralDataGenerator.Open(compressedOut, FileTypeToChar(), name, file.Length, + + return pgpLiteralDataGenerator.Open(compressedOut, FileTypeToChar(), name, file.Length, DateTime.UtcNow); } - #endregion ChainLiteralOut - - #region ChainLiteralStreamOut - - private Stream ChainLiteralStreamOut(Stream compressedOut, Stream inputStream, string name, bool oldFormat) + private Stream ChainLiteralOut(Stream compressedOut, Stream inputStream, string name, bool oldFormat) { PgpLiteralDataGenerator pgpLiteralDataGenerator = new PgpLiteralDataGenerator(oldFormat); return pgpLiteralDataGenerator.Open(compressedOut, FileTypeToChar(), name, inputStream.Length, DateTime.UtcNow); } - #endregion ChainLiteralStreamOut + #endregion ChainLiteralOut - #region InitSignatureGenerator + #region InitSignatureGenerator - private PgpSignatureGenerator InitSignatureGenerator(Stream compressedOut) + private PgpSignatureGenerator InitSignatureGenerator(Stream compressedOut) { PublicKeyAlgorithmTag tag = EncryptionKeys.SigningSecretKey.PublicKey.Algorithm; PgpSignatureGenerator pgpSignatureGenerator = new PgpSignatureGenerator(tag, HashAlgorithmTag); From 2773e926d76ed75495478579e81c9193b7d4184f Mon Sep 17 00:00:00 2001 From: mattosaurus Date: Wed, 29 May 2024 16:33:39 +0100 Subject: [PATCH 2/7] Update to suggested PgpSignatureSubpacketGenerator add method --- PgpCore/PGP.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PgpCore/PGP.cs b/PgpCore/PGP.cs index 7592d75..b1c8db9 100644 --- a/PgpCore/PGP.cs +++ b/PgpCore/PGP.cs @@ -414,7 +414,7 @@ private PgpSignatureGenerator InitSignatureGenerator(Stream compressedOut) foreach (string userId in EncryptionKeys.SigningSecretKey.PublicKey.GetUserIds()) { PgpSignatureSubpacketGenerator subPacketGenerator = new PgpSignatureSubpacketGenerator(); - subPacketGenerator.SetSignerUserId(false, userId); + subPacketGenerator.AddSignerUserId(false, userId); pgpSignatureGenerator.SetHashedSubpackets(subPacketGenerator.Generate()); // Just the first one! break; @@ -437,7 +437,7 @@ private PgpSignatureGenerator InitClearSignatureGenerator(ArmoredOutputStream ar foreach (string userId in EncryptionKeys.SigningSecretKey.PublicKey.GetUserIds()) { PgpSignatureSubpacketGenerator subPacketGenerator = new PgpSignatureSubpacketGenerator(); - subPacketGenerator.SetSignerUserId(false, userId); + subPacketGenerator.AddSignerUserId(false, userId); pgpSignatureGenerator.SetHashedSubpackets(subPacketGenerator.Generate()); // Just the first one! break; From 7fc1c1574ccaed4fa78613631c080859c05b6e48 Mon Sep 17 00:00:00 2001 From: mattosaurus Date: Wed, 29 May 2024 16:34:02 +0100 Subject: [PATCH 3/7] Update package versions --- PgpCore.Tests/PgpCore.Tests.csproj | 6 +++--- PgpCore/PgpCore.csproj | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PgpCore.Tests/PgpCore.Tests.csproj b/PgpCore.Tests/PgpCore.Tests.csproj index ee221ab..802c034 100644 --- a/PgpCore.Tests/PgpCore.Tests.csproj +++ b/PgpCore.Tests/PgpCore.Tests.csproj @@ -8,9 +8,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/PgpCore/PgpCore.csproj b/PgpCore/PgpCore.csproj index ff330fa..1273bef 100644 --- a/PgpCore/PgpCore.csproj +++ b/PgpCore/PgpCore.csproj @@ -121,8 +121,8 @@ - - + + \ No newline at end of file From 4e528d392769b2f909cebaa7826e24a50366112d Mon Sep 17 00:00:00 2001 From: mattosaurus Date: Wed, 29 May 2024 16:35:16 +0100 Subject: [PATCH 4/7] Update version --- PgpCore/PgpCore.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PgpCore/PgpCore.csproj b/PgpCore/PgpCore.csproj index 1273bef..778ceda 100644 --- a/PgpCore/PgpCore.csproj +++ b/PgpCore/PgpCore.csproj @@ -12,8 +12,8 @@ PGP .NET Core 6.4.0.0 6.0.0.0 - 6.4.0 - v6.4.0 - Remove armor option from string methods + 6.4.1 + v6.4.1 - Package updates MIT true true From 2821404591d8a372bdbfd29748d7c3746498c146 Mon Sep 17 00:00:00 2001 From: mattosaurus Date: Wed, 29 May 2024 17:29:39 +0100 Subject: [PATCH 5/7] Update bc version --- PgpCore.Tests/UnitTests/TestBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PgpCore.Tests/UnitTests/TestBase.cs b/PgpCore.Tests/UnitTests/TestBase.cs index f5f9ee9..8b28783 100644 --- a/PgpCore.Tests/UnitTests/TestBase.cs +++ b/PgpCore.Tests/UnitTests/TestBase.cs @@ -12,9 +12,9 @@ namespace PgpCore.Tests.UnitTests public abstract class TestBase { #if NETFRAMEWORK - public const string VERSION = "BouncyCastle.NET Cryptography (net461) v2.1.1+851feee009"; + public const string VERSION = "BouncyCastle.NET Cryptography (net461) v2.4.0+83ebf4a805"; #else - public const string VERSION = "BouncyCastle.NET Cryptography (net6.0) v2.1.1+851feee009"; + public const string VERSION = "BouncyCastle.NET Cryptography (net6.0) v2.4.0+83ebf4a805"; #endif public const string DEFAULTNAME = "name"; public const string TESTNAME = "Test Name"; From 2f0f84ab5bc5365f584071c179f73c8488d2ce13 Mon Sep 17 00:00:00 2001 From: mattosaurus Date: Wed, 29 May 2024 17:33:55 +0100 Subject: [PATCH 6/7] Remove string return method from VerifyClearAsync --- PgpCore/Abstractions/IPGP.VerifyAsync.cs | 2 +- PgpCore/PGP.VerifyAsync.cs | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/PgpCore/Abstractions/IPGP.VerifyAsync.cs b/PgpCore/Abstractions/IPGP.VerifyAsync.cs index 156f2fe..3a8ac28 100644 --- a/PgpCore/Abstractions/IPGP.VerifyAsync.cs +++ b/PgpCore/Abstractions/IPGP.VerifyAsync.cs @@ -14,7 +14,7 @@ public interface IVerifyAsync : IDisposable Task VerifyAsync(string input, bool throwIfEncrypted = false); Task VerifyClearAsync(FileInfo inputFile, FileInfo outputFile = null); Task VerifyClearAsync(Stream inputStream, Stream outputStream = null); - Task VerifyClearAsync(string input, string output = null); + Task VerifyClearAsync(string input); Task VerifyFileAsync(FileInfo inputFile, bool throwIfEncrypted = false); Task VerifyStreamAsync(Stream inputStream, bool throwIfEncrypted = false); diff --git a/PgpCore/PGP.VerifyAsync.cs b/PgpCore/PGP.VerifyAsync.cs index 2af52d5..bf418ad 100644 --- a/PgpCore/PGP.VerifyAsync.cs +++ b/PgpCore/PGP.VerifyAsync.cs @@ -333,24 +333,6 @@ public async Task VerifyClearAsync(string input) return await VerifyClearAsync(inputStream, null); } - /// - /// PGP verify a given string. - /// - /// Plain string to be verified - /// String to write the decrypted data to - public async Task VerifyClearAsync(string input, string output) - { - using (Stream inputStream = await input.GetStreamAsync()) - using (Stream outputStream = new MemoryStream()) - { - bool verified = await VerifyClearAsync(inputStream, outputStream); - - outputStream.Seek(0, SeekOrigin.Begin); - output = await outputStream.GetStringAsync(); - return verified; - } - } - public async Task VerifyClearFileAsync(FileInfo inputFile) => await VerifyClearAsync(inputFile, null); public async Task VerifyClearStreamAsync(Stream inputStream) => await VerifyClearAsync(inputStream, null); From e04bfa8cd89c8b1099bce92d1ea500af998f5e32 Mon Sep 17 00:00:00 2001 From: mattosaurus Date: Thu, 30 May 2024 15:12:50 +0100 Subject: [PATCH 7/7] Use FlushAsync --- PgpCore/PGP.VerifyAsync.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PgpCore/PGP.VerifyAsync.cs b/PgpCore/PGP.VerifyAsync.cs index bf418ad..2242192 100644 --- a/PgpCore/PGP.VerifyAsync.cs +++ b/PgpCore/PGP.VerifyAsync.cs @@ -158,7 +158,7 @@ public async Task VerifyAsync(Stream inputStream, Stream outputStream = nu else throw new PgpException("Message is not a encrypted and signed file or simple signed file."); - outputStream.Flush(); + await outputStream.FlushAsync(); outputStream.Seek(0, SeekOrigin.Begin); return (verified);