Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Awake()
- {
- if (Application.internetReachability != NetworkReachability.NotReachable)
- {
- Debug.Log(GetNistTime());
- }
- }
- public DateTime GetNistTime()
- {
- ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
- var myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
- var response = myHttpWebRequest.GetResponse();
- string todaysDates = response.Headers["date"];
- return DateTime.ParseExact(todaysDates,
- "ddd, dd MMM yyyy HH:mm:ss 'GMT'",
- CultureInfo.InvariantCulture.DateTimeFormat,
- DateTimeStyles.AssumeUniversal);
- }
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement