Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ Thumbs.db

unity_installer_cache
logs
.vscode
7 changes: 6 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
version: v6.0.0
version: v6.0.1
changelog:
- date: 2021-11-30
version: v6.0.1
changes:
- type: improvement
text: "Remove BouncyCastle, JsonFx.Json, MarkerMetro and crypto DLLs. Features works without the need of these libs."
-
changes:
-
Expand Down
28 changes: 0 additions & 28 deletions PubNubUnity/Assets/PubNub/Crypto/MD5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
#if UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
#else
using System.Security.Cryptography;
#endif

namespace PubNubAPI
{
Expand Down Expand Up @@ -676,27 +670,6 @@ protected string EncodeNonAsciiCharacters (string value)
return sb.ToString ();
}

#if UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0
public string PubnubAccessManagerSign(string key, string data)
{
string secret = key;
string message = data;

var encoding = new System.Text.UTF8Encoding();
byte[] keyByte = encoding.GetBytes(secret);
byte[] messageBytes = encoding.GetBytes(message);

//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('/', '_');
}
#else
public string PubnubAccessManagerSign (string key, string data)
{
string secret = key;
Expand All @@ -711,7 +684,6 @@ public string PubnubAccessManagerSign (string key, string data)
return Convert.ToBase64String (hashmessage).Replace ('+', '-').Replace ('/', '_');
}
}
#endif
}
#endregion
}
Expand Down
116 changes: 0 additions & 116 deletions PubNubUnity/Assets/PubNub/Crypto/PubnubCrypto.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
using System;
using System.Text;

#if UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0
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;
using Org.BouncyCastle.Security;
#endif
using System.Security.Cryptography;

using System.IO;

namespace PubNubAPI
Expand Down Expand Up @@ -111,110 +101,7 @@ public bool EncryptOrDecryptFile(bool encrypt, byte[] iv, string filePath, strin

return true;
}

#if UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0
public override string ComputeHashRaw(string input)
{
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);
}

protected override string EncryptOrDecrypt(bool type, string plainStr)
{
//Demo params
string keyString = GetEncryptionKey();

string input = plainStr;
byte[] inputBytes;
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);

if (type)
{
// Encrypt
byte[] iv = new byte[16];
if(UseRandomInitializationVector){
// Generate IV here
iv = new byte[16];
SecureRandom sr = new SecureRandom();
sr.NextBytes(iv);


} else {
iv = System.Text.Encoding.ASCII.GetBytes("0123456789012345");
}

ParametersWithIV keyParamWithIV = new ParametersWithIV(keyParam, iv, 0, iv.Length);

input = EncodeNonAsciiCharacters(input);
inputBytes = Encoding.UTF8.GetBytes(input);
cipher.Init(true, keyParamWithIV);
byte[] outputBytes = new byte[cipher.GetOutputSize(inputBytes.Length)];
int length = cipher.ProcessBytes(inputBytes, outputBytes, 0);
cipher.DoFinal(outputBytes, length); //Do the final block

if(UseRandomInitializationVector){
// Add IV
byte[] message = new byte[outputBytes.Length + iv.Length];
System.Buffer.BlockCopy(iv, 0, message, 0, iv.Length);
System.Buffer.BlockCopy(outputBytes, 0, message, iv.Length, outputBytes.Length);
outputBytes = new byte[message.Length];
System.Buffer.BlockCopy(message, 0, outputBytes, 0, message.Length);
}

return Convert.ToBase64String(outputBytes);
}
else
{
try
{
//Decrypt

inputBytes = Convert.FromBase64CharArray(input.ToCharArray(), 0, input.Length);
byte[] iv = new byte[16];

if(UseRandomInitializationVector){
// Extract IV here
System.Buffer.BlockCopy(inputBytes, 0, iv, 0, 16);
byte[] message = new byte[inputBytes.Length - 16];
System.Buffer.BlockCopy(inputBytes, 16, message, 0, inputBytes.Length-16);
inputBytes = new byte[message.Length];
System.Buffer.BlockCopy(message, 0, inputBytes, 0, message.Length);

} else {
iv = System.Text.Encoding.ASCII.GetBytes("0123456789012345");
}

ParametersWithIV keyParamWithIV = new ParametersWithIV(keyParam, iv, 0, iv.Length);

cipher.Init(false, keyParamWithIV);
byte[] encryptedBytes = new byte[cipher.GetOutputSize(inputBytes.Length)];
int encryptLength = cipher.ProcessBytes(inputBytes, encryptedBytes, 0);
int numOfOutputBytes = cipher.DoFinal(encryptedBytes, encryptLength); //Do the final block
int len = Array.IndexOf(encryptedBytes, (byte)0);
len = (len == -1) ? encryptedBytes.Length : len;
return Encoding.UTF8.GetString(encryptedBytes, 0, len);

}
catch (Exception ex)
{
#if (ENABLE_PUBNUB_LOGGING)
pnLog.WriteToLog(string.Format("Decrypt Error. {0}", ex.ToString()), PNLoggingMethod.LevelVerbose);
#endif
throw ex;
}
}
}
#else
public override string ComputeHashRaw (string input)
{
#if (SILVERLIGHT || WINDOWS_PHONE || MONOTOUCH || __IOS__ || MONODROID || __ANDROID__ || UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_IOS || UNITY_ANDROID || UNITY_5 || UNITY_WEBGL)
Expand Down Expand Up @@ -299,9 +186,6 @@ protected override string EncryptOrDecrypt (bool type, string plainStr)
}
}
}

#endif

}
#endregion
}
Expand Down
4 changes: 3 additions & 1 deletion PubNubUnity/Assets/PubNub/PlayModeTests/PlayModeCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace PubNubAPI.Tests
{

#if !UNITY_WSA && !UNITY_WSA_10_0
class PubnubDemoObject
{
public double VersionID {get; set;}
Expand Down Expand Up @@ -109,4 +110,5 @@ public static PNConfiguration SetPNConfig(bool useCipher, bool withPAM){


}
}
#endif
}
6 changes: 4 additions & 2 deletions PubNubUnity/Assets/PubNub/PlayModeTests/PlayModeTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using UnityEngine;
#if !UNITY_WSA && !UNITY_WSA_10_0
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Text;
using System.IO;
using System.Linq;
using NUnit.Framework;

namespace PubNubAPI.Tests
{
Expand Down Expand Up @@ -5917,3 +5918,4 @@ public IEnumerator TestGrantToken() {

}
}
#endif
2 changes: 1 addition & 1 deletion PubNubUnity/Assets/PubNub/PubNubUnity/PubNubUnityBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace PubNubAPI
public class PubNubUnityBase
{
protected Counter publishMessageCounter;
private const string build = "6.0.0";
private const string build = "6.0.1";
private string pnsdkVersion = string.Format ("PubNub-CSharp-Unity/{0}", build);

public string Version {
Expand Down
Binary file not shown.
122 changes: 0 additions & 122 deletions PubNubUnity/Assets/PubNub/ThirdParty/BouncyCastle.dll.meta

This file was deleted.

Binary file not shown.
Loading