Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #41

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -35,3 +36,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: AssemblyFileVersion("0.0.0.0")]
#endif
8 changes: 6 additions & 2 deletions lib/JSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 19 additions & 12 deletions src/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(DefaultServerCertificateValidator);

public static bool DefaultServerCertificateValidator (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;
Expand Down Expand Up @@ -77,7 +94,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 );
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 );
Expand Down