From 0b968104f0c4dfedc948b12f0eab864e9ec166de Mon Sep 17 00:00:00 2001 From: bergwerkgis Date: Fri, 21 Apr 2017 14:02:56 +0200 Subject: [PATCH 1/7] `MapboxAccess.cs`: Android fix, timeout for `LoadMapboxAccess(), UWP support, `ServerCertificateValidationCallback` --- .../Assets/Mapbox/Core/Unity/MapboxAccess.cs | 340 ++++++++++-------- 1 file changed, 185 insertions(+), 155 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs b/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs index ec76f8f1c..667069878 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs @@ -1,158 +1,188 @@ -namespace Mapbox.Unity -{ - using System.IO; - using UnityEngine; - using System; - using System.Collections; - using Mapbox.Geocoding; - using Mapbox.Directions; - using Mapbox.Platform; - using Mapbox.Unity.Utilities; - - /// - /// Object for retrieving an API token and making http requests. - /// Contains a lazy Geocoder and a lazy Directions for convenience. - /// - public class MapboxAccess : IFileSource - { - readonly string _accessPath = Path.Combine(Application.streamingAssetsPath, Constants.Path.TOKEN_FILE); - - static MapboxAccess _instance = new MapboxAccess(); - - /// - /// The singleton instance. - /// - public static MapboxAccess Instance - { - get - { - return _instance; - } - } - - MapboxAccess() - { - ValidateMapboxAccessFile(); - LoadAccessToken(); - } - - /// - /// The Mapbox API access token. - /// See Mapbox API Congfiguration in Unity. - /// - string _accessToken; - public string AccessToken - { - get - { - return _accessToken; - } - set - { - if (string.IsNullOrEmpty(value)) - { - throw new InvalidTokenException("Please configure your access token in the menu!"); - } - _accessToken = value; - } - } - - void ValidateMapboxAccessFile() - { - if (!Directory.Exists(Application.streamingAssetsPath) || !File.Exists(_accessPath)) - { - throw new InvalidTokenException("Please configure your access token in the menu!"); - } - } - - /// - /// Loads the access token from StreamingAssets. - /// - void LoadAccessToken() - { -#if UNITY_EDITOR || !UNITY_ANDROID - AccessToken = File.ReadAllText(_accessPath); +namespace Mapbox.Unity { + using System.IO; + using UnityEngine; + using System; + using Mapbox.Geocoding; + using Mapbox.Directions; + using Mapbox.Platform; + using System.Net; +#if !NETFX_CORE + using System.Security.Cryptography.X509Certificates; +#endif + using System.Net.Security; + + + /// + /// Object for retrieving an API token and making http requests. + /// Contains a lazy Geocoder and a lazy Directions for convenience. + /// + public class MapboxAccess : IFileSource { + + private readonly string _accessPath = Path.Combine(Application.streamingAssetsPath, Constants.Path.TOKEN_FILE); + + static MapboxAccess _instance = new MapboxAccess(); + + /// + /// The singleton instance. + /// + public static MapboxAccess Instance { + get { + return _instance; + } + } + + + MapboxAccess() { + +#if !NETFX_CORE + ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback; +#endif + ValidateMapboxAccessFile(); + LoadAccessToken(); + } + + + /// + /// The Mapbox API access token. + /// See Mapbox API Congfiguration in Unity. + /// + private string _accessToken; + public string AccessToken { + get { + return _accessToken; + } + set { + if (string.IsNullOrEmpty(value)) { + throw new InvalidTokenException("Please configure your access token in the menu!"); + } + _accessToken = value; + } + } + + + private void ValidateMapboxAccessFile() { +#if !UNITY_ANDROID + if (!Directory.Exists(Application.streamingAssetsPath) || !File.Exists(_accessPath)) { + throw new InvalidTokenException("Please configure your access token in the menu!"); + } +#endif + } + + + /// + /// Loads the access token from StreamingAssets. + /// + private void LoadAccessToken() { + +#if UNITY_EDITOR || !UNITY_ANDROID + AccessToken = File.ReadAllText(_accessPath); +#else + AccessToken = LoadMapboxAccess(); +#endif + } + + + /// + /// Android-specific token file loading. + /// + private string LoadMapboxAccess() { + + var request = new WWW(_accessPath); + // Implement a custom timeout - just in case + // There are 10,000 ticks in a millisecond, or 10 million ticks in a second. + long timeOut = (2 * 10 ^ 7) + DateTime.Now.Ticks; + + while (!request.isDone) { + if (timeOut < DateTime.Now.Ticks) { + throw new InvalidTokenException("Could not load access token!"); + } +#if NETFX_CORE + System.Threading.Tasks.Task.Delay(10).Wait(); #else - Runnable.Run(LoadMapboxAccess()); + System.Threading.Thread.Sleep(10); +#endif + } + return request.text; + } + + + /// + /// Makes an asynchronous url query. + /// + /// The request. + /// URL. + /// Callback. + public IAsyncRequest Request(string url, Action callback) { + + var uriBuilder = new UriBuilder(url); + string accessTokenQuery = "access_token=" + AccessToken; + + if (uriBuilder.Query != null && uriBuilder.Query.Length > 1) { + uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + accessTokenQuery; + } else { + uriBuilder.Query = accessTokenQuery; + } + return new HTTPRequest(uriBuilder.ToString(), callback); + } + + + class InvalidTokenException : Exception { + public InvalidTokenException(string message) : base(message) { + } + } + + + /// + /// Lazy geocoder. + /// + Geocoder _geocoder; + public Geocoder Geocoder { + get { + if (_geocoder == null) { + _geocoder = new Geocoder(this); + } + return _geocoder; + } + } + + + /// + /// Lazy Directions. + /// + Directions _directions; + public Directions Directions { + get { + if (_directions == null) { + _directions = new Directions(this); + } + return _directions; + } + } + + +#if !NETFX_CORE + public bool MyRemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { + bool isOk = true; + // If there are errors in the certificate chain, look at each error to determine the cause. + if (sslPolicyErrors != SslPolicyErrors.None) { + for (int i = 0; i < chain.ChainStatus.Length; i++) { + if (chain.ChainStatus[i].Status != X509ChainStatusFlags.RevocationStatusUnknown) { + chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain; + chain.ChainPolicy.RevocationMode = X509RevocationMode.Online; + chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0); + chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags; + bool chainIsValid = chain.Build((X509Certificate2)certificate); + if (!chainIsValid) { + isOk = false; + } + } + } + } + return isOk; + } #endif - } - - /// - /// Android-specific token file loading. - /// - IEnumerator LoadMapboxAccess() - { - var request = new WWW(_accessPath); - while (!request.isDone) - { - yield return 0; - } - AccessToken = request.text; - } - - /// - /// Makes an asynchronous url query. - /// - /// The request. - /// URL. - /// Callback. - public IAsyncRequest Request(string url, Action callback) - { - var uriBuilder = new UriBuilder(url); - - string accessTokenQuery = "access_token=" + AccessToken; - - if (uriBuilder.Query != null && uriBuilder.Query.Length > 1) - { - uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + accessTokenQuery; - } - else - { - uriBuilder.Query = accessTokenQuery; - } - - return new HTTPRequest(uriBuilder.ToString(), callback); - } - - class InvalidTokenException : Exception - { - public InvalidTokenException(string message) : base(message) - { - } - } - - Geocoder _geocoder; - - /// - /// Lazy geocoder. - /// - public Geocoder Geocoder - { - get - { - if (_geocoder == null) - { - _geocoder = new Geocoder(this); - } - return _geocoder; - } - } - - Directions _directions; - - /// - /// Lazy Directions. - /// - public Directions Directions - { - get - { - if (_directions == null) - { - _directions = new Directions(this); - } - return _directions; - } - } - } + + + + } } From cf590caeca677cc33c73fd850f206d54702a95ec Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Mon, 24 Apr 2017 09:35:55 -0600 Subject: [PATCH 2/7] =?UTF-8?q?Adding=20=E2=80=9Cusing=20Mapbox.Unity.Util?= =?UTF-8?q?ities;=E2=80=9D=20for=20HTTPRequest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Mapbox/Core/Unity/MapboxAccess.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs b/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs index 667069878..5ed206857 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs @@ -1,22 +1,23 @@ namespace Mapbox.Unity { - using System.IO; - using UnityEngine; - using System; - using Mapbox.Geocoding; - using Mapbox.Directions; - using Mapbox.Platform; - using System.Net; + using UnityEngine; + using System.IO; + using System; + using System.Net; + using Mapbox.Geocoding; + using Mapbox.Directions; + using Mapbox.Platform; + using Mapbox.Unity.Utilities; #if !NETFX_CORE - using System.Security.Cryptography.X509Certificates; + using System.Security.Cryptography.X509Certificates; #endif - using System.Net.Security; + using System.Net.Security; - /// - /// Object for retrieving an API token and making http requests. - /// Contains a lazy Geocoder and a lazy Directions for convenience. - /// - public class MapboxAccess : IFileSource { + /// + /// Object for retrieving an API token and making http requests. + /// Contains a lazy Geocoder and a lazy Directions for convenience. + /// + public class MapboxAccess : IFileSource { private readonly string _accessPath = Path.Combine(Application.streamingAssetsPath, Constants.Path.TOKEN_FILE); From 2e70d0ea79f8e31165061da6446a8d9ad2cacba9 Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Mon, 24 Apr 2017 13:57:06 -0600 Subject: [PATCH 3/7] UWP fix for Singleton, from: https://github.com/mapbox/mapbox-sdk-unity/pull/248#issuecomment-295605919 --- sdkproject/Assets/Mapbox/Core/Unity/Utilities/Singleton.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Singleton.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Singleton.cs index 8a2809a87..bba4cad7f 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Singleton.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Singleton.cs @@ -54,8 +54,11 @@ public static T Instance /// private static void CreateInstance() { - if (typeof(MonoBehaviour).IsAssignableFrom(typeof(T))) - { +#if NETFX_CORE + if (typeof(MonoBehaviour).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo())) { +#else + if (typeof(MonoBehaviour).IsAssignableFrom(typeof(T))) { +#endif string singletonName = "_" + typeof(T).Name; GameObject singletonObject = GameObject.Find(singletonName); From 42043e7b6850668b8de116f061052d682744209e Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Mon, 24 Apr 2017 14:05:06 -0600 Subject: [PATCH 4/7] bump submodule --- dependencies/mapbox-sdk-cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/mapbox-sdk-cs b/dependencies/mapbox-sdk-cs index 558cb770a..d4850704d 160000 --- a/dependencies/mapbox-sdk-cs +++ b/dependencies/mapbox-sdk-cs @@ -1 +1 @@ -Subproject commit 558cb770ade50ff737bf4d6001b88af6e68578ba +Subproject commit d4850704db12269df261ff61aea999fef542e3f6 From 1febfa61e5925676ca2f080670aa783a37fd5c19 Mon Sep 17 00:00:00 2001 From: David Rhodes Date: Mon, 24 Apr 2017 14:32:55 -0600 Subject: [PATCH 5/7] removed default scene. --- sdkproject/ProjectSettings/EditorBuildSettings.asset | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sdkproject/ProjectSettings/EditorBuildSettings.asset b/sdkproject/ProjectSettings/EditorBuildSettings.asset index e8f9a8784..6dc24f7df 100644 --- a/sdkproject/ProjectSettings/EditorBuildSettings.asset +++ b/sdkproject/ProjectSettings/EditorBuildSettings.asset @@ -4,6 +4,4 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 - m_Scenes: - - enabled: 1 - path: Assets/Mapbox/Examples/LocationProvider/LocationProvider.unity + m_Scenes: [] From 88905f9a57cd4b00aecb29c459eba35db6744cac Mon Sep 17 00:00:00 2001 From: bergwerkgis Date: Tue, 25 Apr 2017 19:23:12 +0200 Subject: [PATCH 6/7] Singleton.cs add 'using System.Reflection;' for UWP --- .../Mapbox/Core/Unity/Utilities/Singleton.cs | 105 +++++++++--------- 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Singleton.cs b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Singleton.cs index bba4cad7f..4c289ee71 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Singleton.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Utilities/Singleton.cs @@ -17,70 +17,67 @@ //#define SINGLETONS_VISIBLE -namespace Mapbox.Unity.Utilities -{ - using UnityEngine; - using System; - - /// - /// Singleton pattern class. This class detects if T is a MonoBehavior and will - /// make a containing GameObject. - /// - /// The typename of the class to create as a singleton object. - public class Singleton where T : class - { - #region Private Data - static private T sm_Instance = null; - #endregion +namespace Mapbox.Unity.Utilities { - #region Public Properties - /// - /// Returns the Singleton instance of T. - /// - public static T Instance - { - get - { - if (sm_Instance == null) - CreateInstance(); - return sm_Instance; - } - } - #endregion + using UnityEngine; + using System; +#if NETFX_CORE + using System.Reflection; +#endif + + /// + /// Singleton pattern class. This class detects if T is a MonoBehavior and will + /// make a containing GameObject. + /// + /// The typename of the class to create as a singleton object. + public class Singleton where T : class { + #region Private Data + static private T sm_Instance = null; + #endregion + + #region Public Properties + /// + /// Returns the Singleton instance of T. + /// + public static T Instance { + get { + if (sm_Instance == null) + CreateInstance(); + return sm_Instance; + } + } + #endregion - #region Singleton Creation - /// - /// Create the singleton instance. - /// - private static void CreateInstance() - { + #region Singleton Creation + /// + /// Create the singleton instance. + /// + private static void CreateInstance() { #if NETFX_CORE if (typeof(MonoBehaviour).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo())) { #else - if (typeof(MonoBehaviour).IsAssignableFrom(typeof(T))) { + if (typeof(MonoBehaviour).IsAssignableFrom(typeof(T))) { #endif - string singletonName = "_" + typeof(T).Name; + string singletonName = "_" + typeof(T).Name; - GameObject singletonObject = GameObject.Find(singletonName); - if (singletonObject == null) - singletonObject = new GameObject(singletonName); + GameObject singletonObject = GameObject.Find(singletonName); + if (singletonObject == null) + singletonObject = new GameObject(singletonName); #if SINGLETONS_VISIBLE singletonObject.hideFlags = HideFlags.DontSave; #else - singletonObject.hideFlags = HideFlags.HideAndDontSave; + singletonObject.hideFlags = HideFlags.HideAndDontSave; #endif - sm_Instance = singletonObject.GetComponent(); - if (sm_Instance == null) - sm_Instance = singletonObject.AddComponent(typeof(T)) as T; - } - else - { - sm_Instance = Activator.CreateInstance(typeof(T)) as T; - } + sm_Instance = singletonObject.GetComponent(); + if (sm_Instance == null) + sm_Instance = singletonObject.AddComponent(typeof(T)) as T; + } else { + sm_Instance = Activator.CreateInstance(typeof(T)) as T; + } - if (sm_Instance == null) - throw new Exception("Failed to create instance " + typeof(T).Name); - } - #endregion - } + if (sm_Instance == null) + throw new Exception("Failed to create instance " + typeof(T).Name); + } + #endregion + } } \ No newline at end of file From 9ba41cb70fe963d250da4bb3a0ce028ec9274a54 Mon Sep 17 00:00:00 2001 From: Siyu Song Date: Tue, 25 Apr 2017 16:03:59 -0700 Subject: [PATCH 7/7] avoids ticks for timeout in Mapbox access --- .../Assets/Mapbox/Core/Unity/MapboxAccess.cs | 282 +++++++++--------- 1 file changed, 137 insertions(+), 145 deletions(-) diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs b/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs index 5ed206857..526762788 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MapboxAccess.cs @@ -12,178 +12,170 @@ namespace Mapbox.Unity { #endif using System.Net.Security; - /// /// Object for retrieving an API token and making http requests. /// Contains a lazy Geocoder and a lazy Directions for convenience. /// public class MapboxAccess : IFileSource { - private readonly string _accessPath = Path.Combine(Application.streamingAssetsPath, Constants.Path.TOKEN_FILE); - - static MapboxAccess _instance = new MapboxAccess(); + private readonly string _accessPath = Path.Combine(Application.streamingAssetsPath, Constants.Path.TOKEN_FILE); - /// - /// The singleton instance. - /// - public static MapboxAccess Instance { - get { - return _instance; - } - } + static MapboxAccess _instance = new MapboxAccess(); - MapboxAccess() { + /// + /// The singleton instance. + /// + public static MapboxAccess Instance { + get { + return _instance; + } + } + MapboxAccess() { #if !NETFX_CORE - ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback; + ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback; #endif - ValidateMapboxAccessFile(); - LoadAccessToken(); - } - - - /// - /// The Mapbox API access token. - /// See Mapbox API Congfiguration in Unity. - /// - private string _accessToken; - public string AccessToken { - get { - return _accessToken; - } - set { - if (string.IsNullOrEmpty(value)) { - throw new InvalidTokenException("Please configure your access token in the menu!"); - } - _accessToken = value; - } - } - - - private void ValidateMapboxAccessFile() { + ValidateMapboxAccessFile(); + LoadAccessToken(); + } + + + /// + /// The Mapbox API access token. + /// See Mapbox API Congfiguration in Unity. + /// + private string _accessToken; + public string AccessToken { + get { + return _accessToken; + } + set { + if (string.IsNullOrEmpty(value)) { + throw new InvalidTokenException("Please configure your access token in the menu!"); + } + _accessToken = value; + } + } + + + private void ValidateMapboxAccessFile() { #if !UNITY_ANDROID - if (!Directory.Exists(Application.streamingAssetsPath) || !File.Exists(_accessPath)) { - throw new InvalidTokenException("Please configure your access token in the menu!"); - } + if (!Directory.Exists(Application.streamingAssetsPath) || !File.Exists(_accessPath)) { + throw new InvalidTokenException("Please configure your access token in the menu!"); + } #endif - } + } - /// - /// Loads the access token from StreamingAssets. - /// - private void LoadAccessToken() { - + /// + /// Loads the access token from StreamingAssets. + /// + private void LoadAccessToken() { #if UNITY_EDITOR || !UNITY_ANDROID - AccessToken = File.ReadAllText(_accessPath); + AccessToken = File.ReadAllText(_accessPath); #else - AccessToken = LoadMapboxAccess(); + AccessToken = LoadMapboxAccess(); #endif - } - + } - /// - /// Android-specific token file loading. - /// - private string LoadMapboxAccess() { - var request = new WWW(_accessPath); - // Implement a custom timeout - just in case - // There are 10,000 ticks in a millisecond, or 10 million ticks in a second. - long timeOut = (2 * 10 ^ 7) + DateTime.Now.Ticks; + /// + /// Android-specific token file loading. + /// + private string LoadMapboxAccess() { - while (!request.isDone) { - if (timeOut < DateTime.Now.Ticks) { - throw new InvalidTokenException("Could not load access token!"); - } + var request = new WWW(_accessPath); + // Implement a custom timeout - just in case + var timeout = Time.realtimeSinceStartup + 5f; + while (!request.isDone) { + if (Time.realtimeSinceStartup > timeout) { + throw new InvalidTokenException("Could not load access token!"); + } #if NETFX_CORE - System.Threading.Tasks.Task.Delay(10).Wait(); + System.Threading.Tasks.Task.Delay(10).Wait(); #else - System.Threading.Thread.Sleep(10); + System.Threading.Thread.Sleep(10); #endif - } - return request.text; - } - - - /// - /// Makes an asynchronous url query. - /// - /// The request. - /// URL. - /// Callback. - public IAsyncRequest Request(string url, Action callback) { - - var uriBuilder = new UriBuilder(url); - string accessTokenQuery = "access_token=" + AccessToken; - - if (uriBuilder.Query != null && uriBuilder.Query.Length > 1) { - uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + accessTokenQuery; - } else { - uriBuilder.Query = accessTokenQuery; - } - return new HTTPRequest(uriBuilder.ToString(), callback); - } - - - class InvalidTokenException : Exception { - public InvalidTokenException(string message) : base(message) { - } - } - - - /// - /// Lazy geocoder. - /// - Geocoder _geocoder; - public Geocoder Geocoder { - get { - if (_geocoder == null) { - _geocoder = new Geocoder(this); - } - return _geocoder; - } - } - - - /// - /// Lazy Directions. - /// - Directions _directions; - public Directions Directions { - get { - if (_directions == null) { - _directions = new Directions(this); - } - return _directions; - } - } + } + return request.text; + } + + + /// + /// Makes an asynchronous url query. + /// + /// The request. + /// URL. + /// Callback. + public IAsyncRequest Request(string url, Action callback) { + + var uriBuilder = new UriBuilder(url); + string accessTokenQuery = "access_token=" + AccessToken; + + if (uriBuilder.Query != null && uriBuilder.Query.Length > 1) { + uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + accessTokenQuery; + } else { + uriBuilder.Query = accessTokenQuery; + } + return new HTTPRequest(uriBuilder.ToString(), callback); + } + + + class InvalidTokenException : Exception { + public InvalidTokenException(string message) : base(message) { + } + } + + + /// + /// Lazy geocoder. + /// + Geocoder _geocoder; + public Geocoder Geocoder { + get { + if (_geocoder == null) { + _geocoder = new Geocoder(this); + } + return _geocoder; + } + } + + + /// + /// Lazy Directions. + /// + Directions _directions; + public Directions Directions { + get { + if (_directions == null) { + _directions = new Directions(this); + } + return _directions; + } + } #if !NETFX_CORE - public bool MyRemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { - bool isOk = true; - // If there are errors in the certificate chain, look at each error to determine the cause. - if (sslPolicyErrors != SslPolicyErrors.None) { - for (int i = 0; i < chain.ChainStatus.Length; i++) { - if (chain.ChainStatus[i].Status != X509ChainStatusFlags.RevocationStatusUnknown) { - chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain; - chain.ChainPolicy.RevocationMode = X509RevocationMode.Online; - chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0); - chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags; - bool chainIsValid = chain.Build((X509Certificate2)certificate); - if (!chainIsValid) { - isOk = false; - } - } - } - } - return isOk; - } + public bool MyRemoteCertificateValidationCallback(System.Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { + bool isOk = true; + // If there are errors in the certificate chain, look at each error to determine the cause. + if (sslPolicyErrors != SslPolicyErrors.None) { + for (int i = 0; i < chain.ChainStatus.Length; i++) { + if (chain.ChainStatus[i].Status != X509ChainStatusFlags.RevocationStatusUnknown) { + chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain; + chain.ChainPolicy.RevocationMode = X509RevocationMode.Online; + chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0); + chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags; + bool chainIsValid = chain.Build((X509Certificate2)certificate); + if (!chainIsValid) { + isOk = false; + } + } + } + } + return isOk; + } #endif - - - - } + } }