diff --git a/source/Runtime/Client/SimpleWebClient.cs b/source/Runtime/Client/SimpleWebClient.cs index 0c69af9..44ca7ee 100644 --- a/source/Runtime/Client/SimpleWebClient.cs +++ b/source/Runtime/Client/SimpleWebClient.cs @@ -17,12 +17,12 @@ public enum ClientState /// public abstract class SimpleWebClient { - public static SimpleWebClient Create(int maxMessageSize, int maxMessagesPerTick, TcpConfig tcpConfig) + public static SimpleWebClient Create(int maxMessageSize, int maxMessagesPerTick, TcpConfig tcpConfig, bool allowSSLErrors = false) { #if UNITY_WEBGL && !UNITY_EDITOR return new WebSocketClientWebGl(maxMessageSize, maxMessagesPerTick); #else - return new WebSocketClientStandAlone(maxMessageSize, maxMessagesPerTick, tcpConfig); + return new WebSocketClientStandAlone(maxMessageSize, maxMessagesPerTick, tcpConfig, allowSSLErrors); #endif } diff --git a/source/Runtime/Client/StandAlone/ClientSslHelper.cs b/source/Runtime/Client/StandAlone/ClientSslHelper.cs index 4b5d79e..25ed1a4 100644 --- a/source/Runtime/Client/StandAlone/ClientSslHelper.cs +++ b/source/Runtime/Client/StandAlone/ClientSslHelper.cs @@ -1,4 +1,5 @@ -using System; +using Codice.CM.Common; +using System; using System.IO; using System.Net.Security; using System.Net.Sockets; @@ -8,6 +9,13 @@ namespace JamesFrowen.SimpleWeb { internal class ClientSslHelper { + private readonly bool allowErrors; + + public ClientSslHelper(bool allowErrors) + { + this.allowErrors = allowErrors; + } + internal bool TryCreateStream(Connection conn, Uri uri) { NetworkStream stream = conn.client.GetStream(); @@ -36,12 +44,20 @@ Stream CreateStream(NetworkStream stream, Uri uri) return sslStream; } - static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) + bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { - // Do not allow this client to communicate with unauthenticated servers. - // only accept if no errors - return sslPolicyErrors == SslPolicyErrors.None; + if (sslPolicyErrors == SslPolicyErrors.None) + return true; + + if (allowErrors) + { + Log.Error($"Cert had Errors {sslPolicyErrors}, but allowErrors is true"); + return true; + } + + // Do not allow this client to communicate with unauthenticated servers. + return false; } } } diff --git a/source/Runtime/Client/StandAlone/WebSocketClientStandAlone.cs b/source/Runtime/Client/StandAlone/WebSocketClientStandAlone.cs index db1a438..43990aa 100644 --- a/source/Runtime/Client/StandAlone/WebSocketClientStandAlone.cs +++ b/source/Runtime/Client/StandAlone/WebSocketClientStandAlone.cs @@ -11,12 +11,12 @@ public class WebSocketClientStandAlone : SimpleWebClient readonly TcpConfig tcpConfig; Connection conn; - internal WebSocketClientStandAlone(int maxMessageSize, int maxMessagesPerTick, TcpConfig tcpConfig) : base(maxMessageSize, maxMessagesPerTick) + internal WebSocketClientStandAlone(int maxMessageSize, int maxMessagesPerTick, TcpConfig tcpConfig, bool allowSSLErrors) : base(maxMessageSize, maxMessagesPerTick) { #if UNITY_WEBGL && !UNITY_EDITOR throw new NotSupportedException(); #else - sslHelper = new ClientSslHelper(); + sslHelper = new ClientSslHelper(allowSSLErrors); handshake = new ClientHandshake(); this.tcpConfig = tcpConfig; #endif