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/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) }; } } 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/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..d2e9265a1 100644 --- a/src/Api/PubnubApi/Security/SecureMessage.cs +++ b/src/Api/PubnubApi/Security/SecureMessage.cs @@ -71,7 +71,8 @@ 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); + 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); } else 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 diff --git a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs index 890e03d64..d4f091639 100644 --- a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs +++ b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs @@ -793,6 +793,135 @@ 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() + { + PNConfiguration config = new PNConfiguration(new UserId("test")); + config.SubscribeKey = "demo"; + config.PublishKey = "demo"; + + return config; + } } -} \ No newline at end of file +}