diff --git a/.pubnub.yml b/.pubnub.yml index 1c9054573..37ae351a4 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,15 @@ name: c-sharp -version: "5.3.0" +version: "5.4.0" schema: 1 scm: github.com/pubnub/c-sharp changelog: + - date: 2021-12-16 + version: v5.4.0 + changes: + - type: bug + text: "Replaced BouncyCastle lib with System.Security.Cryptography.Algorithms." + - type: bug + text: "Added try/catch for publish operation to catch exceptions." - date: 2021-11-16 version: v5.3.0 changes: @@ -614,7 +621,7 @@ features: - QUERY-PARAM supported-platforms: - - version: Pubnub 'C#' 5.3.0 + version: Pubnub 'C#' 5.4.0 platforms: - Windows 10 and up - Windows Server 2008 and up @@ -624,7 +631,7 @@ supported-platforms: - .Net Framework 4.5 - .Net Framework 4.6.1+ - - version: PubnubPCL 'C#' 5.3.0 + version: PubnubPCL 'C#' 5.4.0 platforms: - Xamarin.Android - Xamarin.iOS @@ -643,7 +650,7 @@ supported-platforms: - .Net Standard 2.1 - .Net Core - - version: PubnubUWP 'C#' 5.3.0 + version: PubnubUWP 'C#' 5.4.0 platforms: - Windows Phone 10 - Universal Windows Apps @@ -667,7 +674,7 @@ sdks: distribution-type: source distribution-repository: Github package-name: Pubnub - location: https://github.com/pubnub/c-sharp/releases/tag/v5.3.0.0 + location: https://github.com/pubnub/c-sharp/releases/tag/v5.4.0.0 requires: - name: ".Net" @@ -964,7 +971,7 @@ sdks: distribution-type: source distribution-repository: GitHub package-name: PubNubPCL - location: https://github.com/pubnub/c-sharp/releases/tag/v5.3.0.0 + location: https://github.com/pubnub/c-sharp/releases/tag/v5.4.0.0 requires: - name: ".Net Core" @@ -1337,7 +1344,7 @@ sdks: distribution-type: source distribution-repository: Github package-name: PubnubUWP - location: https://github.com/pubnub/c-sharp/releases/tag/v5.3.0.0 + location: https://github.com/pubnub/c-sharp/releases/tag/v5.4.0.0 requires: - name: "Universal Windows Platform Development" diff --git a/CHANGELOG b/CHANGELOG index e19d3c758..515cd9265 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +v5.4.0 - December 16 2021 +----------------------------- +- Fixed: replaced BouncyCastle lib with System.Security.Cryptography.Algorithms. +- Fixed: added try/catch for publish operation to catch exceptions. + v5.3.0 - November 16 2021 ----------------------------- - Added: added RevokeToken feature. diff --git a/src/Api/PubnubApi/EndPoint/PubSub/PublishOperation.cs b/src/Api/PubnubApi/EndPoint/PubSub/PublishOperation.cs index f587b65a3..4dbf7fd7d 100644 --- a/src/Api/PubnubApi/EndPoint/PubSub/PublishOperation.cs +++ b/src/Api/PubnubApi/EndPoint/PubSub/PublishOperation.cs @@ -205,67 +205,81 @@ internal void Publish(string channel, object message, bool storeInHistory, int t return; } - string requestMethodName = (this.httpPost) ? "POST" : "GET"; - IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null && !string.IsNullOrEmpty(PubnubInstance.InstanceId) && PubnubTokenMgrCollection.ContainsKey(PubnubInstance.InstanceId)) ? PubnubTokenMgrCollection[PubnubInstance.InstanceId] : null, (PubnubInstance != null) ? PubnubInstance.InstanceId : ""); - - Uri request = urlBuilder.BuildPublishRequest(requestMethodName, "", channel, message, storeInHistory, ttl, metaData, null, externalQueryParam); - RequestState requestState = new RequestState(); - requestState.Channels = new [] { channel }; - requestState.ResponseType = PNOperationType.PNPublishOperation; - requestState.PubnubCallback = callback; - requestState.Reconnect = false; - requestState.EndPointOperation = this; + try + { + string requestMethodName = (this.httpPost) ? "POST" : "GET"; + IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null && !string.IsNullOrEmpty(PubnubInstance.InstanceId) && PubnubTokenMgrCollection.ContainsKey(PubnubInstance.InstanceId)) ? PubnubTokenMgrCollection[PubnubInstance.InstanceId] : null, (PubnubInstance != null) ? PubnubInstance.InstanceId : ""); - string json = ""; + Uri request = urlBuilder.BuildPublishRequest(requestMethodName, "", channel, message, storeInHistory, ttl, metaData, null, externalQueryParam); - if (this.httpPost) - { - requestState.UsePostMethod = true; - string postMessage = JsonEncodePublishMsg(message); - byte[] postData = Encoding.UTF8.GetBytes(postMessage); - UrlProcessRequest(request, requestState, false, postData).ContinueWith(r => + requestState.Channels = new[] { channel }; + requestState.ResponseType = PNOperationType.PNPublishOperation; + requestState.PubnubCallback = callback; + requestState.Reconnect = false; + requestState.EndPointOperation = this; + + string json = ""; + + if (this.httpPost) { - json = r.Result.Item1; - }, TaskContinuationOptions.ExecuteSynchronously).Wait(); - } - else - { - UrlProcessRequest(request, requestState, false).ContinueWith(r => + requestState.UsePostMethod = true; + string postMessage = JsonEncodePublishMsg(message); + byte[] postData = Encoding.UTF8.GetBytes(postMessage); + UrlProcessRequest(request, requestState, false, postData).ContinueWith(r => + { + json = r.Result.Item1; + }, TaskContinuationOptions.ExecuteSynchronously).Wait(); + } + else { - json = r.Result.Item1; - }, TaskContinuationOptions.ExecuteSynchronously).Wait(); - } - - if (!string.IsNullOrEmpty(json)) - { - List result = ProcessJsonResponse(requestState, json); + UrlProcessRequest(request, requestState, false).ContinueWith(r => + { + json = r.Result.Item1; + }, TaskContinuationOptions.ExecuteSynchronously).Wait(); + } - if (result != null && result.Count >= 3) + if (!string.IsNullOrEmpty(json)) { - int publishStatus; - Int32.TryParse(result[0].ToString(), out publishStatus); - if (publishStatus == 1) + List result = ProcessJsonResponse(requestState, json); + + if (result != null && result.Count >= 3) { - ProcessResponseCallbacks(result, requestState); + int publishStatus; + Int32.TryParse(result[0].ToString(), out publishStatus); + if (publishStatus == 1) + { + ProcessResponseCallbacks(result, requestState); + } + else + { + PNStatusCategory category = PNStatusCategoryHelper.GetPNStatusCategory(400, result[1].ToString()); + PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNPublishOperation, category, requestState, 400, new PNException(json)); + if (requestState.PubnubCallback != null) + { + requestState.PubnubCallback.OnResponse(default(PNPublishResult), status); + } + } } else { - PNStatusCategory category = PNStatusCategoryHelper.GetPNStatusCategory(400, result[1].ToString()); - PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNPublishOperation, category, requestState, 400, new PNException(json)); - if (requestState.PubnubCallback != null) - { - requestState.PubnubCallback.OnResponse(default(PNPublishResult), status); - } + ProcessResponseCallbacks(result, requestState); } } - else + + CleanUp(); + } + catch (Exception ex) + { + int statusCode = PNStatusCodeHelper.GetHttpStatusCode(ex.ToString()); + PNStatusCategory category = PNStatusCategoryHelper.GetPNStatusCategory(statusCode, ex.ToString()); + PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNPublishOperation, category, requestState, statusCode, new PNException(ex.ToString())); + if (requestState.PubnubCallback != null) { - ProcessResponseCallbacks(result, requestState); + requestState.PubnubCallback.OnResponse(default(PNPublishResult), status); } - } - CleanUp(); + } } internal async Task> Publish(string channel, object message, bool storeInHistory, int ttl, Dictionary metaData, Dictionary externalQueryParam) @@ -290,56 +304,66 @@ internal async Task> Publish(string channel, object me return ret; } - string requestMethodName = (this.httpPost) ? "POST" : "GET"; - IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null && !string.IsNullOrEmpty(PubnubInstance.InstanceId) && PubnubTokenMgrCollection.ContainsKey(PubnubInstance.InstanceId)) ? PubnubTokenMgrCollection[PubnubInstance.InstanceId] : null, (PubnubInstance != null) ? PubnubInstance.InstanceId : ""); - - Uri request = urlBuilder.BuildPublishRequest(requestMethodName, "", channel, message, storeInHistory, ttl, metaData, null, externalQueryParam); - RequestState requestState = new RequestState(); - requestState.Channels = new[] { channel }; - requestState.ResponseType = PNOperationType.PNPublishOperation; - requestState.Reconnect = false; - requestState.EndPointOperation = this; + try + { + string requestMethodName = (this.httpPost) ? "POST" : "GET"; + IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null && !string.IsNullOrEmpty(PubnubInstance.InstanceId) && PubnubTokenMgrCollection.ContainsKey(PubnubInstance.InstanceId)) ? PubnubTokenMgrCollection[PubnubInstance.InstanceId] : null, (PubnubInstance != null) ? PubnubInstance.InstanceId : ""); - Tuple JsonAndStatusTuple; + Uri request = urlBuilder.BuildPublishRequest(requestMethodName, "", channel, message, storeInHistory, ttl, metaData, null, externalQueryParam); - if (this.httpPost) - { - requestState.UsePostMethod = true; - string postMessage = JsonEncodePublishMsg(message); - byte[] postData = Encoding.UTF8.GetBytes(postMessage); - JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false, postData).ConfigureAwait(false); - } - else - { - JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false).ConfigureAwait(false); - } - ret.Status = JsonAndStatusTuple.Item2; - string json = JsonAndStatusTuple.Item1; + requestState.Channels = new[] { channel }; + requestState.ResponseType = PNOperationType.PNPublishOperation; + requestState.Reconnect = false; + requestState.EndPointOperation = this; - if (!string.IsNullOrEmpty(json)) - { - List result = ProcessJsonResponse(requestState, json); + Tuple JsonAndStatusTuple; + + if (this.httpPost) + { + requestState.UsePostMethod = true; + string postMessage = JsonEncodePublishMsg(message); + byte[] postData = Encoding.UTF8.GetBytes(postMessage); + JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false, postData).ConfigureAwait(false); + } + else + { + JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false).ConfigureAwait(false); + } + ret.Status = JsonAndStatusTuple.Item2; + string json = JsonAndStatusTuple.Item1; - if (result != null && result.Count >= 3) + if (!string.IsNullOrEmpty(json)) { - int publishStatus; - Int32.TryParse(result[0].ToString(), out publishStatus); - if (publishStatus == 1) + List result = ProcessJsonResponse(requestState, json); + + if (result != null && result.Count >= 3) { - List resultList = ProcessJsonResponse(requestState, json); - if (resultList != null && resultList.Count > 0) + int publishStatus; + Int32.TryParse(result[0].ToString(), out publishStatus); + if (publishStatus == 1) { - ResponseBuilder responseBuilder = new ResponseBuilder(config, jsonLibrary, pubnubLog); - PNPublishResult responseResult = responseBuilder.JsonToObject(resultList, true); - if (responseResult != null) + List resultList = ProcessJsonResponse(requestState, json); + if (resultList != null && resultList.Count > 0) { - ret.Result = responseResult; + ResponseBuilder responseBuilder = new ResponseBuilder(config, jsonLibrary, pubnubLog); + PNPublishResult responseResult = responseBuilder.JsonToObject(resultList, true); + if (responseResult != null) + { + ret.Result = responseResult; + } } } } } } + catch (Exception ex) + { + int statusCode = PNStatusCodeHelper.GetHttpStatusCode(ex.ToString()); + PNStatusCategory category = PNStatusCategoryHelper.GetPNStatusCategory(statusCode, ex.ToString()); + PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNPublishOperation, category, requestState, statusCode, new PNException(ex.ToString())); + ret.Status = status; + } return ret; } diff --git a/src/Api/PubnubApi/Properties/AssemblyInfo.cs b/src/Api/PubnubApi/Properties/AssemblyInfo.cs index db587f8b3..5d637fa29 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("5.3.0.0")] -[assembly: AssemblyFileVersion("5.3.0.0")] +[assembly: AssemblyVersion("5.4.0.0")] +[assembly: AssemblyFileVersion("5.4.0.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 12aa0d8e0..026660ed3 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -13,7 +13,7 @@ Pubnub - 5.3.0.0 + 5.4.0.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -21,7 +21,8 @@ http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png true https://github.com/pubnub/c-sharp/ - Added RevokeToken feature. + Replaced BouncyCastle lib with System.Security.Cryptography.Algorithms. +Added try/catch for publish operation to catch exceptions. 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 @@ -85,9 +86,6 @@ - - None - None @@ -99,9 +97,6 @@ - - None - @@ -110,8 +105,8 @@ - - None + + 4.3.0 diff --git a/src/Api/PubnubApi/Security/PubnubCrypto.cs b/src/Api/PubnubApi/Security/PubnubCrypto.cs index f05117ea4..30803d616 100644 --- a/src/Api/PubnubApi/Security/PubnubCrypto.cs +++ b/src/Api/PubnubApi/Security/PubnubCrypto.cs @@ -2,17 +2,7 @@ using System.Text; using System.Globalization; -#if !NETSTANDARD10 && !NETSTANDARD11 using System.Security.Cryptography; -#endif - -#if !NET35 -using Org.BouncyCastle.Crypto.Digests; -using Org.BouncyCastle.Crypto.Engines; -using Org.BouncyCastle.Crypto.Modes; -using Org.BouncyCastle.Crypto.Paddings; -using Org.BouncyCastle.Crypto.Parameters; -#endif namespace PubnubApi { @@ -37,19 +27,10 @@ public PubnubCrypto(string cipher_key) protected override string ComputeHashRaw(string input) { -#if NET35 HashAlgorithm algorithm = SHA256.Create(); Byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input); Byte[] hashedBytes = algorithm.ComputeHash(inputBytes); return BitConverter.ToString(hashedBytes); -#else - Sha256Digest algorithm = new Sha256Digest(); - Byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input); - Byte[] bufferBytes = new byte[algorithm.GetDigestSize()]; - algorithm.BlockUpdate(inputBytes, 0, inputBytes.Length); - algorithm.DoFinal(bufferBytes, 0); - return BitConverter.ToString(bufferBytes); -#endif } protected override string EncryptOrDecrypt(bool type, string dataStr, bool dynamicIV) @@ -137,7 +118,7 @@ protected override byte[] EncryptOrDecrypt(bool type, byte[] dataBytes, bool dyn { LoggingMethod.WriteToLog(pubnubLog, string.Format("DateTime {0} IV = {1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), GetDisplayableBytes(ivBytes)), config.LogVerbosity); } -#if NET35 + Aes aesAlg = Aes.Create(); aesAlg.KeySize = 256; aesAlg.BlockSize = 128; @@ -145,34 +126,15 @@ protected override byte[] EncryptOrDecrypt(bool type, byte[] dataBytes, bool dyn aesAlg.Padding = PaddingMode.PKCS7; aesAlg.IV = ivBytes; aesAlg.Key = System.Text.Encoding.UTF8.GetBytes(keyString); -#else - byte[] iv = ivBytes; - byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(keyString); - - //Set up - AesEngine engine = new AesEngine(); - CbcBlockCipher blockCipher = new CbcBlockCipher(engine); //CBC - PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(blockCipher); //Default scheme is PKCS5/PKCS7 - KeyParameter keyParam = new KeyParameter(keyBytes); - ParametersWithIV keyParamWithIV = new ParametersWithIV(keyParam, iv, 0, iv.Length); -#endif - if (type) { // Encrypt byte[] outputBytes = null; -#if NET35 ICryptoTransform crypto = aesAlg.CreateEncryptor(); byte[] plainBytes = dataBytes; outputBytes = crypto.TransformFinalBlock(plainBytes, 0, plainBytes.Length); -#else - byte[] inputBytes = dataBytes; - cipher.Init(true, keyParamWithIV); - outputBytes = new byte[cipher.GetOutputSize(inputBytes.Length)]; - int length = cipher.ProcessBytes(inputBytes, outputBytes, 0); - cipher.DoFinal(outputBytes, length); //Do the final block -#endif + byte[] newOutputBytes = null; if (dynamicIV) { @@ -193,22 +155,12 @@ protected override byte[] EncryptOrDecrypt(bool type, byte[] dataBytes, bool dyn try { //Decrypt -#if NET35 byte[] decryptedBytes = dataBytes; ICryptoTransform decrypto = aesAlg.CreateDecryptor(); var data = decrypto.TransformFinalBlock(decryptedBytes, 0, decryptedBytes.Length); newOutputBytes = data; -#else - byte[] inputBytes = dataBytes; - cipher.Init(false, keyParamWithIV); - byte[] encryptedBytes = new byte[cipher.GetOutputSize(inputBytes.Length)]; - var encryptLength = cipher.ProcessBytes(inputBytes, encryptedBytes, 0); - var lastBytesLength = cipher.DoFinal(encryptedBytes, encryptLength); //Do the final block - var totalBytesLength = encryptLength + lastBytesLength; - newOutputBytes = new byte[totalBytesLength]; - Array.Copy(encryptedBytes, newOutputBytes, totalBytesLength); -#endif + return newOutputBytes; } catch (Exception ex) diff --git a/src/Api/PubnubApi/Security/PubnubCryptoBase.cs b/src/Api/PubnubApi/Security/PubnubCryptoBase.cs index 7dcadeca1..dc1d33201 100644 --- a/src/Api/PubnubApi/Security/PubnubCryptoBase.cs +++ b/src/Api/PubnubApi/Security/PubnubCryptoBase.cs @@ -2,14 +2,7 @@ using System.Globalization; using System.Text; using System.Text.RegularExpressions; - -#if NET35 using System.Security.Cryptography; -#else -using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Crypto.Parameters; -using Org.BouncyCastle.Security; -#endif namespace PubnubApi { @@ -163,24 +156,11 @@ public string PubnubAccessManagerSign(string key, string data) byte[] keyByte = encoding.GetBytes(secret); byte[] messageBytes = encoding.GetBytes(message); -#if NET35 using (var hmacsha256 = new HMACSHA256(keyByte)) { byte[] hashmessage = hmacsha256.ComputeHash(messageBytes); return Convert.ToBase64String(hashmessage).Replace('+', '-').Replace('/', '_'); } -#else - - //http://mycsharp.de/wbb2/thread.php?postid=3550104 - KeyParameter paramKey = new KeyParameter(keyByte); - IMac mac = MacUtilities.GetMac("HMac-SHA256"); - mac.Init(paramKey); - mac.Reset(); - mac.BlockUpdate(messageBytes, 0, messageBytes.Length); - byte[] hashmessage = new byte[mac.GetMacSize()]; - mac.DoFinal(hashmessage, 0); - return Convert.ToBase64String(hashmessage).Replace('+', '-').Replace('/', '_'); -#endif } public static byte[] PubnubAccessManagerSign(string key, byte[] dataBytes) @@ -191,24 +171,11 @@ public static byte[] PubnubAccessManagerSign(string key, byte[] dataBytes) byte[] keyByte = encoding.GetBytes(secret); byte[] messageBytes = dataBytes; -#if NET35 using (var hmacsha256 = new HMACSHA256(keyByte)) { byte[] hashmessage = hmacsha256.ComputeHash(messageBytes); return hashmessage; } -#else - - //http://mycsharp.de/wbb2/thread.php?postid=3550104 - KeyParameter paramKey = new KeyParameter(keyByte); - IMac mac = MacUtilities.GetMac("HMac-SHA256"); - mac.Init(paramKey); - mac.Reset(); - mac.BlockUpdate(messageBytes, 0, messageBytes.Length); - byte[] hashmessage = new byte[mac.GetMacSize()]; - mac.DoFinal(hashmessage, 0); - return hashmessage; -#endif } public string GetHashRaw(string input) diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index 02072eec9..36cd7b363 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -14,7 +14,7 @@ PubnubPCL - 5.3.0.0 + 5.4.0.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -22,7 +22,8 @@ http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png true https://github.com/pubnub/c-sharp/ - Added RevokeToken feature. + Replaced BouncyCastle lib with System.Security.Cryptography.Algorithms. +Added try/catch for publish operation to catch exceptions. 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 @@ -585,6 +586,7 @@ None + @@ -595,9 +597,6 @@ - - None - None diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index b200c5252..92e7f0daf 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -15,7 +15,7 @@ PubnubUWP - 5.3.0.0 + 5.4.0.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -23,7 +23,8 @@ http://pubnub.s3.amazonaws.com/2011/powered-by-pubnub/pubnub-icon-600x600.png true https://github.com/pubnub/c-sharp/ - Added RevokeToken feature. + Replaced BouncyCastle lib with System.Security.Cryptography.Algorithms. +Added try/catch for publish operation to catch exceptions. 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 @@ -673,9 +674,7 @@ 9.0.1 - - 1.8.1.2 - + diff --git a/src/UnitTests/AcceptanceTests/Features/revoke-token.feature b/src/UnitTests/AcceptanceTests/Features/revoke-token.feature index e7713a3dc..f83efad2d 100644 --- a/src/UnitTests/AcceptanceTests/Features/revoke-token.feature +++ b/src/UnitTests/AcceptanceTests/Features/revoke-token.feature @@ -30,7 +30,7 @@ Feature: Revoke an access token Given a token When I revoke a token Then an error is returned - * the error status code is 403 + * the error status code is 400 * the error message is 'Feature disabled' * the error source is 'revoke' * the error detail message is 'Token revocation is disabled.' diff --git a/src/UnitTests/MockServerPubnubApiPCL/MockServerPubnubApiPCL.csproj b/src/UnitTests/MockServerPubnubApiPCL/MockServerPubnubApiPCL.csproj index 3118e0f63..f58740da6 100644 --- a/src/UnitTests/MockServerPubnubApiPCL/MockServerPubnubApiPCL.csproj +++ b/src/UnitTests/MockServerPubnubApiPCL/MockServerPubnubApiPCL.csproj @@ -42,12 +42,6 @@ - - - None - - - 4.0.0 diff --git a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs index f5d96dbe6..b812d6659 100644 --- a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs +++ b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs @@ -308,8 +308,12 @@ public void TestLocalFileEncryptionFromPath() { IPubnubUnitTest pubnubUnitTest = new PubnubUnitTest(); pubnubUnitTest.IV = new byte[16] { 133, 126, 158, 123, 43, 95, 96, 90, 215, 178, 17, 73, 166, 130, 79, 156 }; - string sourceFile = @"C:\Pandu\temp\new\input\file_upload_original.txt"; - string destFile = @"C:\Pandu\temp\new\input\file_upload_original_encrypted.txt"; + string sourceFile = "fileupload.txt"; + string destFile = "fileupload_encrypted.txt"; + if (System.IO.File.Exists(destFile)) + { + System.IO.File.Delete(destFile); + } PNConfiguration config = new PNConfiguration(); Pubnub pn = new Pubnub(config); pn.EncryptFile(sourceFile, destFile, "enigma"); @@ -320,8 +324,12 @@ public void TestLocalFileEncryptionFromPath() [Test] public void TestLocalFileDecryptionFromPath() { - string sourceFile = @"C:\Pandu\temp\new\input\file_image_enc.jpg"; - string destFile = @"C:\Pandu\temp\new\input\file_image_enc_decrypted_to_original.jpg"; + string sourceFile = "fileupload_enc.txt"; + string destFile = "fileupload_enc_decrypted_to_original.txt"; + if (System.IO.File.Exists(destFile)) + { + System.IO.File.Delete(destFile); + } PNConfiguration config = new PNConfiguration(); Pubnub pn = new Pubnub(config); pn.DecryptFile(sourceFile, destFile, "enigma"); diff --git a/src/UnitTests/PubnubApi.Tests/PubnubApi.Tests.csproj b/src/UnitTests/PubnubApi.Tests/PubnubApi.Tests.csproj index ede288552..e668d9912 100644 --- a/src/UnitTests/PubnubApi.Tests/PubnubApi.Tests.csproj +++ b/src/UnitTests/PubnubApi.Tests/PubnubApi.Tests.csproj @@ -84,5 +84,6 @@ + diff --git a/src/UnitTests/PubnubApi.Tests/WhenFileIsRequested.cs b/src/UnitTests/PubnubApi.Tests/WhenFileIsRequested.cs index 8683cd66a..b03fef58b 100644 --- a/src/UnitTests/PubnubApi.Tests/WhenFileIsRequested.cs +++ b/src/UnitTests/PubnubApi.Tests/WhenFileIsRequested.cs @@ -69,7 +69,7 @@ public static void Init() Thread.Sleep(1000); - grantManualEvent.WaitOne(); + grantManualEvent.WaitOne(2000); pubnub.Destroy(); pubnub.PubnubUnitTest = null; @@ -152,7 +152,7 @@ public static void ThenSendFileShouldReturnSuccess() mre.Set(); })); Thread.Sleep(1000); - mre.WaitOne(); + mre.WaitOne(3 * 1000 * 60); if (receivedMessage) { @@ -169,11 +169,12 @@ public static void ThenSendFileShouldReturnSuccess() mre.Set(); })); Thread.Sleep(1000); - mre.WaitOne(); + mre.WaitOne(2 * 1000 * 60); } if (receivedMessage) { + System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072; //Need this line for .net 3.5/4.0/4.5 receivedMessage = false; mre = new ManualResetEvent(false); pubnub.DownloadFile().Channel(channelName).FileId(fileId).FileName(fileName).Execute(new PNDownloadFileResultExt((result, status) => @@ -186,7 +187,7 @@ public static void ThenSendFileShouldReturnSuccess() } mre.Set(); })); - mre.WaitOne(); + mre.WaitOne(2 * 1000 * 60); } if (receivedMessage) @@ -204,7 +205,7 @@ public static void ThenSendFileShouldReturnSuccess() mre.Set(); })); Thread.Sleep(1000); - mre.WaitOne(); + mre.WaitOne(2 * 1000 * 60); } @@ -298,11 +299,12 @@ public static async Task ThenWithAsyncSendFileShouldReturnSuccess() mre.Set(); })); Thread.Sleep(1000); - mre.WaitOne(); + mre.WaitOne(2 * 1000 * 60); if (receivedMessage) { + System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072; //Need this line for .net 3.5/4.0/4.5 receivedMessage = false; mre = new ManualResetEvent(false); pubnub.DownloadFile().Channel(channelName).FileId(fileId).FileName(fileName).Execute(new PNDownloadFileResultExt((result, status) => @@ -314,7 +316,7 @@ public static async Task ThenWithAsyncSendFileShouldReturnSuccess() } mre.Set(); })); - mre.WaitOne(); + mre.WaitOne(2 * 1000 * 60); } if (receivedMessage) @@ -332,7 +334,7 @@ public static async Task ThenWithAsyncSendFileShouldReturnSuccess() mre.Set(); })); Thread.Sleep(1000); - mre.WaitOne(); + mre.WaitOne(2 * 1000 * 60); } diff --git a/src/UnitTests/PubnubApi.Tests/fileupload_enc.txt b/src/UnitTests/PubnubApi.Tests/fileupload_enc.txt new file mode 100644 index 000000000..0dade6638 Binary files /dev/null and b/src/UnitTests/PubnubApi.Tests/fileupload_enc.txt differ diff --git a/src/UnitTests/PubnubApiPCL.Tests/PubnubApiPCL.Tests.csproj b/src/UnitTests/PubnubApiPCL.Tests/PubnubApiPCL.Tests.csproj index 6c4cab259..d763a794a 100644 --- a/src/UnitTests/PubnubApiPCL.Tests/PubnubApiPCL.Tests.csproj +++ b/src/UnitTests/PubnubApiPCL.Tests/PubnubApiPCL.Tests.csproj @@ -107,5 +107,6 @@ + diff --git a/src/UnitTests/PubnubApiPCL.Tests/fileupload_enc.txt b/src/UnitTests/PubnubApiPCL.Tests/fileupload_enc.txt new file mode 100644 index 000000000..0dade6638 Binary files /dev/null and b/src/UnitTests/PubnubApiPCL.Tests/fileupload_enc.txt differ