From b28962dbd86cb0004a8b9277b152af315e791637 Mon Sep 17 00:00:00 2001 From: Roman Savrulin Date: Wed, 20 May 2015 18:18:10 +0300 Subject: [PATCH 1/5] Make project compilable in unity5 --- lib/JSON.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/JSON.cs b/lib/JSON.cs index ae06abd..ea9683d 100644 --- a/lib/JSON.cs +++ b/lib/JSON.cs @@ -241,8 +241,12 @@ protected static string ParseString (char[] json, ref int index, ref bool succes if (!(success = UInt32.TryParse (new string (json, index, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out codePoint))) { return ""; } - // convert the integer codepoint to a unicode char and add to string - s.Append (Char.ConvertFromUtf32 ((int)codePoint)); + try{ + // convert the integer codepoint to a unicode char and add to string + s.Append (Char.ConvertFromUtf32 ((int)codePoint)); + }catch(Exception e){ + s.Append ( "" ); + } // skip 4 chars index += 4; } else { From 841ead552124dbfeb4cec17b05a6f915c72bf64f Mon Sep 17 00:00:00 2001 From: Roman Savrulin Date: Wed, 20 May 2015 18:19:06 +0300 Subject: [PATCH 2/5] add missing file for previous commit --- src/Request.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request.cs b/src/Request.cs index c9b358d..31a3358 100644 --- a/src/Request.cs +++ b/src/Request.cs @@ -77,7 +77,7 @@ public Request( string method, string uri, WWWForm form ) this.method = method; this.uri = new Uri (uri); this.bytes = form.data; - foreach ( DictionaryEntry entry in form.headers ) + foreach ( var entry in form.headers ) { this.AddHeader( (string)entry.Key, (string)entry.Value ); } From a221735c839245b28f83855ad64083bbfe08cb21 Mon Sep 17 00:00:00 2001 From: Roman Savrulin Date: Mon, 25 May 2015 18:51:06 +0300 Subject: [PATCH 3/5] Added feature for setting a custom Server SSL Certificate verifier --- src/Request.cs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Request.cs b/src/Request.cs index 31a3358..85c681b 100644 --- a/src/Request.cs +++ b/src/Request.cs @@ -24,6 +24,23 @@ public enum RequestState { Waiting, Reading, Done } + public class CertVerifier + { + public delegate bool CertVerifierCB (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors); + + public static CertVerifierCB verifier = new CertVerifierCB(ValidateServerCertificate); + + public static bool ValidateServerCertificate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) + { + #if !UNITY_EDITOR + System.Console.WriteLine( "NET: SSL Cert: " + sslPolicyErrors.ToString() ); + #else + Debug.LogWarning("SSL Cert Error: " + sslPolicyErrors.ToString ()); + #endif + return true; + } + } + public class Request { public static bool LogAllRequests = false; @@ -160,7 +177,7 @@ private void GetResponse() { using (var stream = client.GetStream ()) { var ostream = stream as Stream; if (uri.Scheme.ToLower() == "https") { - ostream = new SslStream (stream, false, new RemoteCertificateValidationCallback (ValidateServerCertificate)); + ostream = new SslStream (stream, false, new RemoteCertificateValidationCallback (CertVerifier.verifier)); try { var ssl = ostream as SslStream; ssl.AuthenticateAsClient (uri.Host); @@ -301,16 +318,6 @@ public string Text { set { bytes = System.Text.Encoding.UTF8.GetBytes (value); } } - public static bool ValidateServerCertificate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) - { -#if !UNITY_EDITOR - System.Console.WriteLine( "NET: SSL Cert: " + sslPolicyErrors.ToString() ); -#else - Debug.LogWarning("SSL Cert Error: " + sslPolicyErrors.ToString ()); -#endif - return true; - } - void WriteToStream( Stream outputStream ) { var stream = new BinaryWriter( outputStream ); From 328863b1a09b9968633e4cc2154a4e52a3806544 Mon Sep 17 00:00:00 2001 From: Roman Savrulin Date: Thu, 28 May 2015 16:34:51 +0300 Subject: [PATCH 4/5] Cert validator method rename --- src/Request.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Request.cs b/src/Request.cs index 85c681b..24d581c 100644 --- a/src/Request.cs +++ b/src/Request.cs @@ -28,9 +28,9 @@ public class CertVerifier { public delegate bool CertVerifierCB (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors); - public static CertVerifierCB verifier = new CertVerifierCB(ValidateServerCertificate); + public static CertVerifierCB verifier = new CertVerifierCB(DefaultServerCertificateValidator); - public static bool ValidateServerCertificate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) + public static bool DefaultServerCertificateValidator (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { #if !UNITY_EDITOR System.Console.WriteLine( "NET: SSL Cert: " + sslPolicyErrors.ToString() ); From f449c4ed2e4f7c27f4056eddfba7d4d5edf1e4d8 Mon Sep 17 00:00:00 2001 From: Roman Savrulin Date: Wed, 17 Jun 2015 13:24:10 +0300 Subject: [PATCH 5/5] Exclude Assembly.cs when compiling in UNITY --- AssemblyInfo.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs index 89dae49..1dc2c6b 100644 --- a/AssemblyInfo.cs +++ b/AssemblyInfo.cs @@ -2,6 +2,7 @@ using System.Runtime.InteropServices; using System.Runtime.Serialization; +#if !(UNITY_5_0 || UNITY_4_6 || UNITY_4_5 || UNITY_4_3 || UNITY_4_2 || UNITY_4_1 ) // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. @@ -35,3 +36,4 @@ // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("0.0.0.0")] [assembly: AssemblyFileVersion("0.0.0.0")] +#endif \ No newline at end of file