internal static bool CertificateErrorHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
 {
     if (sslPolicyErrors == SslPolicyErrors.None)
     {
         return(true);
     }
     if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch)
     {
         Tracer.TraceInformation("Accepting SSL certificate because the only error is invalid hostname", new object[0]);
         return(true);
     }
     if (ServerToServerEwsCallingContext.AllowInternalUntrustedCerts())
     {
         Tracer.TraceInformation("Accepting SSL certificate because registry config AllowInternalUntrustedCerts tells to ignore errors", new object[0]);
         return(true);
     }
     Tracer.TraceInformation("Failed because SSL certificate contains the following errors: {0}", new object[]
     {
         sslPolicyErrors
     });
     return(false);
 }
        public override void SetServiceApiContext(ExchangeServiceBinding binding, string mailboxEmailAddress)
        {
            base.SetServiceApiContext(binding, mailboxEmailAddress);
            OAuthCredentials oauthCredentials = binding.Credentials as OAuthCredentials;

            if (oauthCredentials != null)
            {
                oauthCredentials.ClientRequestId = new Guid?(binding.HttpContext.ClientRequestId);
            }
            if (!ServerToServerEwsCallingContext.IsCrossPremiseServiceBinding(binding))
            {
                binding.OpenAsAdminOrSystemService = new OpenAsAdminOrSystemServiceType
                {
                    LogonType     = SpecialLogonType.Admin,
                    ConnectingSID = new ConnectingSIDType
                    {
                        Item = new PrimarySmtpAddressType
                        {
                            Value = mailboxEmailAddress
                        }
                    }
                };
            }
        }