From bf242814f94d8620e863badf5662950283903977 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Mon, 27 Nov 2023 13:33:45 +0100 Subject: [PATCH 1/6] fix file crypto --- src/Api/PubnubApi/EndPoint/Files/DownloadFileOperation.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Api/PubnubApi/EndPoint/Files/DownloadFileOperation.cs b/src/Api/PubnubApi/EndPoint/Files/DownloadFileOperation.cs index d8fc2d43b..9e5b11c6b 100644 --- a/src/Api/PubnubApi/EndPoint/Files/DownloadFileOperation.cs +++ b/src/Api/PubnubApi/EndPoint/Files/DownloadFileOperation.cs @@ -173,7 +173,8 @@ private void ProcessFileDownloadRequest(Dictionary externalQuery } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine(ex.ToString()); + System.Diagnostics.Debug.WriteLine("{0}\nMessage might be not encrypted, returning as is...", ex.ToString()); + outputBytes = item1Bytes; } } PNDownloadFileResult result = new PNDownloadFileResult(); @@ -241,7 +242,9 @@ private async Task> ProcessFileDownloadRequest(Di } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine(ex.ToString()); + System.Diagnostics.Debug.WriteLine("{0}\nMessage might be not encrypted, returning as is...", ex.ToString()); + outputBytes = item1Bytes; + ret.Status = new PNStatus { Error = true, ErrorData = new PNErrorData("Decryption error", ex) }; } } From b9a05ff1268bccae0df313fa1f507f41576b71ae Mon Sep 17 00:00:00 2001 From: Xavrax Date: Mon, 27 Nov 2023 19:15:02 +0100 Subject: [PATCH 2/6] This should return as expected --- src/Api/PubnubApi/PubnubCoreBase.cs | 13 ++++++++++++- src/Api/PubnubApi/Security/SecureMessage.cs | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Api/PubnubApi/PubnubCoreBase.cs b/src/Api/PubnubApi/PubnubCoreBase.cs index 2b3a78313..25643fb06 100644 --- a/src/Api/PubnubApi/PubnubCoreBase.cs +++ b/src/Api/PubnubApi/PubnubCoreBase.cs @@ -724,8 +724,19 @@ private void ResponseToUserCallback(List result, PNOperationType type } Announce(status); + + LoggingMethod.WriteToLog( + currentLog, + string.Format( + CultureInfo.InvariantCulture, + "Failed to decrypt message on channel {0} in ResponseToUserCallback due to exception={1}.\nMessage might be not encrypted, returning as is...", + currentMessageChannel, + ex + ), + currentConfig.LogVerbosity + ); } - object decodeMessage = (decryptMessage == "**DECRYPT ERROR**") ? decryptMessage : jsonLib.DeserializeToObject(decryptMessage); + object decodeMessage = jsonLib.DeserializeToObject((decryptMessage == "**DECRYPT ERROR**") ? payload.ToString() : decryptMessage); payloadContainer.Add(decodeMessage); } diff --git a/src/Api/PubnubApi/Security/SecureMessage.cs b/src/Api/PubnubApi/Security/SecureMessage.cs index 892b514aa..f0041c7ac 100644 --- a/src/Api/PubnubApi/Security/SecureMessage.cs +++ b/src/Api/PubnubApi/Security/SecureMessage.cs @@ -71,7 +71,7 @@ public List HistoryDecodeDecryptLoop(PNOperationType type, List FetchHistoryDecodeDecryptLoop(PNOperationType type, Dicti errorCallback.OnResponse(default(T), status); #endregion } - object decodeMessage = (decryptMessage == "**DECRYPT ERROR**") ? decryptMessage : jsonLib.DeserializeToObject(decryptMessage); + object decodeMessage = jsonLib.DeserializeToObject((decryptMessage == "**DECRYPT ERROR**") ? decryptMessage : decryptMessage); dicDecrypt.Add(kvpValue.Key, decodeMessage); } else From 7a9e7d36eddec48f9d7caf5998728049c4c331e0 Mon Sep 17 00:00:00 2001 From: Xavrax Date: Mon, 27 Nov 2023 19:16:57 +0100 Subject: [PATCH 3/6] needed log --- src/Api/PubnubApi/Security/SecureMessage.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Api/PubnubApi/Security/SecureMessage.cs b/src/Api/PubnubApi/Security/SecureMessage.cs index f0041c7ac..d2e9265a1 100644 --- a/src/Api/PubnubApi/Security/SecureMessage.cs +++ b/src/Api/PubnubApi/Security/SecureMessage.cs @@ -71,6 +71,7 @@ public List HistoryDecodeDecryptLoop(PNOperationType type, List FetchHistoryDecodeDecryptLoop(PNOperationType type, Dicti errorCallback.OnResponse(default(T), status); #endregion } + pubnubLog.WriteToLog("Failed to decrypt message!\nMessage might be not encrypted, returning as is..."); object decodeMessage = jsonLib.DeserializeToObject((decryptMessage == "**DECRYPT ERROR**") ? decryptMessage : decryptMessage); dicDecrypt.Add(kvpValue.Key, decodeMessage); } From e94f707ff01115449a6ca4c5db28201decd498db Mon Sep 17 00:00:00 2001 From: Xavrax Date: Tue, 28 Nov 2023 00:35:56 +0100 Subject: [PATCH 4/6] add ut for encryptions --- .../PubnubApi.Tests/EncryptionTests.cs | 132 +++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs index 890e03d64..029490ab8 100644 --- a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs +++ b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs @@ -793,6 +793,136 @@ public void TestPAMv3Signature() Assert.AreEqual("v2.k80LsDMD-sImA8rCBj-ntRKhZ8mSjHY8Ivngt9W3Yc4", signature); } + [Test] + async public void TestSubscribeDecryption() + { + bool done = false; + PNConfiguration config = CreateTestConfig(); + config.CryptoModule = new CryptoModule(new AesCbcCryptor("enigma"), new List { new LegacyCryptor("enigma") }); + + Pubnub sut = new Pubnub(config); + + sut.AddListener(new SubscribeCallbackExt( + (pb, message) => + { + Assert.AreEqual("test", message.Message); + done = true; + }, + (pb, presence) => {}, + (pb, status) => {} + ) + ); + + sut.Subscribe().Channels(new[] { "test" }).Execute(); + + Pubnub sender = new Pubnub(CreateTestConfig()); + + // Rust generated encrypted message + await sender.Publish() + .Channel("test") + .Message("UE5FRAFBQ1JIEALf+E65kseYJwTw2J6BUk9MePHiCcBCS+8ykXLkBIOA") + .ExecuteAsync(); + + // It will wait until the message is received or unit test timeout is reached + while (!done) + { + await System.Threading.Tasks.Task.Delay(100); + } + } + + [Test] + async public void TestSubscribeDecryptionOnNonEncryptedMessage() + { + bool done = false; + PNConfiguration config = CreateTestConfig(); + config.CryptoModule = new CryptoModule(new AesCbcCryptor("enigma"), new List { new LegacyCryptor("enigma") }); + + Pubnub sut = new Pubnub(config); + + sut.AddListener(new SubscribeCallbackExt( + (pb, message) => + { + Assert.AreEqual("test", message.Message); + done = true; + }, + (pb, presence) => {}, + (pb, status) => {} + ) + ); + + sut.Subscribe().Channels(new[] { "test" }).Execute(); + + Pubnub sender = new Pubnub(CreateTestConfig()); + + // Rust generated encrypted message + await sender.Publish() + .Channel("test") + .Message("test") + .ExecuteAsync(); + + // It will wait until the message is received or unit test timeout is reached + while (!done) + { + await System.Threading.Tasks.Task.Delay(100); + } + } + + [Test] + async public void TestHistoryDecryption() + { + PNConfiguration config = CreateTestConfig(); + config.CryptoModule = new CryptoModule(new AesCbcCryptor("enigma"), new List { new LegacyCryptor("enigma") }); + + Pubnub sut = new Pubnub(config); + + Pubnub sender = new Pubnub(CreateTestConfig()); + + // Rust generated encrypted message + await sender.Publish() + .Channel("test") + .Message("UE5FRAFBQ1JIEALf+E65kseYJwTw2J6BUk9MePHiCcBCS+8ykXLkBIOA") + .ExecuteAsync(); + + PNResult result = await sut.History() + .Channel("test") + .Count(1) + .ExecuteAsync(); + + Assert.AreEqual("test", result.Result.Messages[0].Entry); + } + + [Test] + async public void TestHistoryDecryptionOnNonEncryptedMessage() + { + PNConfiguration config = CreateTestConfig(); + config.CryptoModule = new CryptoModule(new AesCbcCryptor("enigma"), new List { new LegacyCryptor("enigma") }); + + Pubnub sut = new Pubnub(config); + + Pubnub sender = new Pubnub(CreateTestConfig()); + + // Rust generated encrypted message + await sender.Publish() + .Channel("test") + .Message("test") + .ExecuteAsync(); + + PNResult result = await sut.History() + .Channel("test") + .Count(1) + .ExecuteAsync(); + Assert.AreEqual("test", result.Result.Messages[0].Entry); + } + + private PNConfiguration CreateTestConfig() + { + // TODO: @mohitpubnub Can you check if is it possible to test that without using the real infra? + PNConfiguration config = new PNConfiguration(new UserId("test")); + config.SubscribeKey = "demo"; + config.PublishKey = "demo"; + + return config; + } } -} \ No newline at end of file +} From 4b62eaf77dfaacc86024a72a7a7393fb2a7fffac Mon Sep 17 00:00:00 2001 From: Mohit Tejani Date: Tue, 28 Nov 2023 11:52:53 +0530 Subject: [PATCH 5/6] clean up. todo: use of TestHarness for avoiding prod call --- src/UnitTests/PubnubApi.Tests/EncryptionTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs index 029490ab8..d4f091639 100644 --- a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs +++ b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs @@ -917,7 +917,6 @@ await sender.Publish() private PNConfiguration CreateTestConfig() { - // TODO: @mohitpubnub Can you check if is it possible to test that without using the real infra? PNConfiguration config = new PNConfiguration(new UserId("test")); config.SubscribeKey = "demo"; config.PublishKey = "demo"; From 2e4d09ee2d962bea0c160d49ca27b4e9b26e748c Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Tue, 28 Nov 2023 06:32:13 +0000 Subject: [PATCH 6/6] PubNub SDK v6.19.4.0 release. --- .pubnub.yml | 19 ++++++++++++------- CHANGELOG | 4 ++++ src/Api/PubnubApi/Properties/AssemblyInfo.cs | 4 ++-- src/Api/PubnubApi/PubnubApi.csproj | 4 ++-- src/Api/PubnubApiPCL/PubnubApiPCL.csproj | 4 ++-- src/Api/PubnubApiUWP/PubnubApiUWP.csproj | 4 ++-- src/Api/PubnubApiUnity/PubnubApiUnity.csproj | 2 +- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 4645c9627..48f91eed7 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,13 @@ name: c-sharp -version: "6.19.3" +version: "6.19.4" schema: 1 scm: github.com/pubnub/c-sharp changelog: + - date: 2023-11-28 + version: v6.19.4 + changes: + - type: bug + text: "Handle unencrypted message while getting messages with crypto." - date: 2023-10-31 version: v6.19.3 changes: @@ -756,7 +761,7 @@ features: - QUERY-PARAM supported-platforms: - - version: Pubnub 'C#' 6.19.3 + version: Pubnub 'C#' 6.19.4 platforms: - Windows 10 and up - Windows Server 2008 and up @@ -766,7 +771,7 @@ supported-platforms: - .Net Framework 4.5 - .Net Framework 4.6.1+ - - version: PubnubPCL 'C#' 6.19.3 + version: PubnubPCL 'C#' 6.19.4 platforms: - Xamarin.Android - Xamarin.iOS @@ -786,7 +791,7 @@ supported-platforms: - .Net Core - .Net 6.0 - - version: PubnubUWP 'C#' 6.19.3 + version: PubnubUWP 'C#' 6.19.4 platforms: - Windows Phone 10 - Universal Windows Apps @@ -810,7 +815,7 @@ sdks: distribution-type: source distribution-repository: GitHub package-name: Pubnub - location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.3.0 + location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.4.0 requires: - name: ".Net" @@ -1093,7 +1098,7 @@ sdks: distribution-type: source distribution-repository: GitHub package-name: PubNubPCL - location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.3.0 + location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.4.0 requires: - name: ".Net Core" @@ -1452,7 +1457,7 @@ sdks: distribution-type: source distribution-repository: GitHub package-name: PubnubUWP - location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.3.0 + location: https://github.com/pubnub/c-sharp/releases/tag/v6.19.4.0 requires: - name: "Universal Windows Platform Development" diff --git a/CHANGELOG b/CHANGELOG index e76fac81d..bbd9e2b31 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +v6.19.4 - November 28 2023 +----------------------------- +- Fixed: handle unencrypted message while getting messages with crypto. + v6.19.3 - October 31 2023 ----------------------------- - Fixed: fixes issue of applying default serializer settings. diff --git a/src/Api/PubnubApi/Properties/AssemblyInfo.cs b/src/Api/PubnubApi/Properties/AssemblyInfo.cs index eca0b80ff..c1729a64a 100644 --- a/src/Api/PubnubApi/Properties/AssemblyInfo.cs +++ b/src/Api/PubnubApi/Properties/AssemblyInfo.cs @@ -11,8 +11,8 @@ [assembly: AssemblyProduct("Pubnub C# SDK")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("6.19.3.0")] -[assembly: AssemblyFileVersion("6.19.3.0")] +[assembly: AssemblyVersion("6.19.4.0")] +[assembly: AssemblyFileVersion("6.19.4.0")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index 0253fbb74..97fe7984b 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -14,7 +14,7 @@ Pubnub - 6.19.3.0 + 6.19.4.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -22,7 +22,7 @@ http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png true https://github.com/pubnub/c-sharp/ - Fixes issue of applying default serializer settings. + Handle unencrypted message while getting messages with crypto. Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index d42818c29..879fa6efa 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -15,7 +15,7 @@ PubnubPCL - 6.19.3.0 + 6.19.4.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -23,7 +23,7 @@ http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png true https://github.com/pubnub/c-sharp/ - Fixes issue of applying default serializer settings. + Handle unencrypted message while getting messages with crypto. Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index ed831a32f..2ebea91c7 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -16,7 +16,7 @@ PubnubUWP - 6.19.3.0 + 6.19.4.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -24,7 +24,7 @@ http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png true https://github.com/pubnub/c-sharp/ - Fixes issue of applying default serializer settings. + Handle unencrypted message while getting messages with crypto. Web Data Push Real-time Notifications ESB Message Broadcasting Distributed Computing PubNub is a Massively Scalable Web Push Service for Web and Mobile Games. This is a cloud-based service for broadcasting messages to thousands of web and mobile clients simultaneously diff --git a/src/Api/PubnubApiUnity/PubnubApiUnity.csproj b/src/Api/PubnubApiUnity/PubnubApiUnity.csproj index 23df35d20..a368be819 100644 --- a/src/Api/PubnubApiUnity/PubnubApiUnity.csproj +++ b/src/Api/PubnubApiUnity/PubnubApiUnity.csproj @@ -15,7 +15,7 @@ PubnubApiUnity - 6.19.3.0 + 6.19.4.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub