示例#1
0
 protected virtual void FillRequestProperties(HttpWebRequest request)
 {
     request.ContentType     = "text/xml;charset=utf-8";
     request.UserAgent       = this.UserAgent;
     request.PreAuthenticate = true;
     request.CookieContainer = new CookieContainer();
     if (this.IgnoreSslCertError)
     {
         CertificateValidationManager.RegisterCallback(ServiceValidatorBase.ComponentId, new RemoteCertificateValidationCallback(ServiceValidatorBase.TrustAllCertValidationCallback));
         CertificateValidationManager.SetComponentId(request, ServiceValidatorBase.ComponentId);
     }
 }
        public Exception Ping(Uri url)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }
            ExTraceGlobals.VerboseTracer.TraceDebug <Uri>((long)this.GetHashCode(), "[ProtocolPingStrategyBase::Ctor]: Testing server with URL {0}.", url);
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

            httpWebRequest.ServicePoint.ConnectionLimit = HttpProxySettings.ServicePointConnectionLimit.Value;
            httpWebRequest.Method          = "HEAD";
            httpWebRequest.Timeout         = ProtocolPingStrategyBase.DownLevelServerPingTimeout.Value;
            httpWebRequest.PreAuthenticate = true;
            httpWebRequest.UserAgent       = "HttpProxy.ClientAccessServer2010Ping";
            httpWebRequest.KeepAlive       = false;
            if (!HttpProxySettings.UseDefaultWebProxy.Value)
            {
                httpWebRequest.Proxy = NullWebProxy.Instance;
            }
            httpWebRequest.ServerCertificateValidationCallback = ProxyApplication.RemoteCertificateValidationCallback;
            CertificateValidationManager.SetComponentId(httpWebRequest, Constants.CertificateValidationComponentId);
            this.PrepareRequest(httpWebRequest);
            try
            {
                using (httpWebRequest.GetResponse())
                {
                }
            }
            catch (WebException ex)
            {
                ExTraceGlobals.VerboseTracer.TraceWarning <WebException>((long)this.GetHashCode(), "[ProtocolPingStrategyBase::TestServer]: Web exception: {0}.", ex);
                if (!this.IsWebExceptionExpected(ex))
                {
                    return(ex);
                }
            }
            catch (Exception ex2)
            {
                ExTraceGlobals.VerboseTracer.TraceError <Exception>((long)this.GetHashCode(), "[ProtocolPingStrategyBase::TestServer]: General exception {0}.", ex2);
                return(ex2);
            }
            finally
            {
                try
                {
                    httpWebRequest.Abort();
                }
                catch
                {
                }
            }
            return(null);
        }
示例#3
0
 private HttpWebRequest ConfigureRequest(HttpWebRequest request)
 {
     request.CookieContainer = this.CookieContainer;
     request.Proxy           = this.Proxy;
     request.Credentials     = this.Credentials;
     request.UserAgent       = this.UserAgent;
     request.Timeout         = this.Timeout;
     if (!string.IsNullOrEmpty(this.componentId))
     {
         CertificateValidationManager.SetComponentId(request, this.componentId);
     }
     return(this.ApplyHeadersToRequest(request));
 }
示例#4
0
        // Token: 0x06001261 RID: 4705 RVA: 0x0006FF40 File Offset: 0x0006E140
        internal static HttpWebRequest CreateHttpWebRequestForProxying(OwaContext owaContext, Uri requestUri)
        {
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUri);

            httpWebRequest.UnsafeAuthenticatedConnectionSharing = true;
            httpWebRequest.PreAuthenticate   = true;
            httpWebRequest.AllowAutoRedirect = false;
            httpWebRequest.Credentials       = CredentialCache.DefaultNetworkCredentials.GetCredential(requestUri, "Kerberos");
            if (httpWebRequest.Credentials == null)
            {
                throw new OwaInvalidOperationException("Can't get credentials for the proxy request");
            }
            httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip;
            CertificateValidationManager.SetComponentId(httpWebRequest, requestUri.IsLoopback ? "OWA_IgnoreCertErrors" : "OWA");
            GccUtils.CopyClientIPEndpointsForServerToServerProxy(owaContext.HttpContext, httpWebRequest);
            return(httpWebRequest);
        }
示例#5
0
        private HttpWebRequest CopyClientRequest(HttpRequest clientrequest, Uri proxyuri)
        {
            string         b = HttpRequestHeader.Authorization.ToString();
            HttpWebRequest httpWebRequest = this.CreateWebRequest(proxyuri);

            httpWebRequest.Method = clientrequest.HttpMethod;
            for (int i = 0; i < clientrequest.Headers.Count; i++)
            {
                string text = clientrequest.Headers.Keys[i];
                if ((!(text == b) || !this.proxyInfo.CanImpersonate) && !WebHeaderCollection.IsRestricted(text))
                {
                    httpWebRequest.Headers[text] = clientrequest.Headers[text];
                }
            }
            CertificateValidationManager.SetComponentId(httpWebRequest, "AirSync");
            foreach (string text2 in this.proxyInfo.AdditionalHeaders.Keys)
            {
                httpWebRequest.Headers[text2] = this.proxyInfo.AdditionalHeaders[text2];
            }
            if (GlobalSettings.IsGCCEnabled)
            {
                if (GlobalSettings.AreGccStoredSecretKeysValid)
                {
                    string text3 = httpWebRequest.Headers["x-gcc-proxyinfo"];
                    if (string.IsNullOrEmpty(text3) || (!string.IsNullOrEmpty(text3) && !ProxyHandler.HasValidAuthString(text3)))
                    {
                        StringBuilder stringBuilder = new StringBuilder(GccUtils.GetAuthStringForThisServer());
                        stringBuilder.Append(", ");
                        stringBuilder.Append(clientrequest.ServerVariables["REMOTE_ADDR"]);
                        stringBuilder.Append(", ");
                        stringBuilder.Append(clientrequest.ServerVariables["LOCAL_ADDR"]);
                        httpWebRequest.Headers["x-gcc-proxyinfo"] = stringBuilder.ToString();
                    }
                }
                else
                {
                    AirSyncDiagnostics.LogPeriodicEvent(AirSyncEventLogConstants.Tuple_NoGccStoredSecretKey, "NoGccStoredSecretKey", new string[0]);
                    AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, null, "No gcc stored secret key");
                }
            }
            httpWebRequest.Referer     = clientrequest.Url.AbsoluteUri;
            httpWebRequest.ContentType = clientrequest.ContentType;
            httpWebRequest.UserAgent   = clientrequest.UserAgent;
            return(httpWebRequest);
        }
示例#6
0
 private static bool TryProxyAutodiscoverRequest(ProxyRequestData proxyRequestData, string redirectServer, out string rawResponse)
 {
     ExTraceGlobals.AuthenticationTracer.TraceDebug <string>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest. Entrypoint. redirectServer = {0}.", redirectServer);
     rawResponse = null;
     if (string.IsNullOrEmpty(redirectServer))
     {
         ExTraceGlobals.AuthenticationTracer.TraceError <string>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest. This is an invalid server name. redirectServer = {0}.", redirectServer);
         return(false);
     }
     try
     {
         HttpWebRequest httpWebRequest = proxyRequestData.CloneRequest(redirectServer);
         CertificateValidationManager.SetComponentId(httpWebRequest, "AutodiscoverProxy");
         using (WebResponse response = httpWebRequest.GetResponse())
         {
             using (Stream responseStream = response.GetResponseStream())
             {
                 rawResponse = AutodiscoverProxy.GetResponse(responseStream);
                 if (rawResponse == null)
                 {
                     ExTraceGlobals.AuthenticationTracer.TraceError <string>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest. received wrong number of user response. rawResponse = {0}.", rawResponse);
                     return(false);
                 }
                 ExTraceGlobals.AuthenticationTracer.TraceDebug <string, string>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest. Received response for user. redirectServer = {0}, rawResponse = {1}.", redirectServer, rawResponse);
             }
         }
     }
     catch (LocalizedException arg)
     {
         ExTraceGlobals.AuthenticationTracer.TraceError <LocalizedException>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest caught with a LocalizedException. LocalizedException = {0}.", arg);
         return(false);
     }
     catch (WebException arg2)
     {
         ExTraceGlobals.AuthenticationTracer.TraceError <WebException>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest caught with a WebException. WebException = {0}.", arg2);
         return(false);
     }
     return(true);
 }
            protected override WebRequest GetWebRequest(Uri uri)
            {
                WebRequest webRequest = base.GetWebRequest(uri);

                if (webRequest is HttpWebRequest)
                {
                    HttpWebRequest request = webRequest as HttpWebRequest;
                    if (this.trustSslCert)
                    {
                        CertificateValidationManager.SetComponentId(request, "Microsoft.Exchange.Data.Directory.SystemConfiguration.AuthMetadataClient.NoSsl");
                    }
                    else
                    {
                        CertificateValidationManager.SetComponentId(request, "Microsoft.Exchange.Data.Directory.SystemConfiguration.AuthMetadataClient");
                    }
                }
                if (this.Timeout != 0)
                {
                    webRequest.Timeout = this.Timeout;
                }
                return(webRequest);
            }
        protected override IAsyncResult BeginInvoke()
        {
            this.timer = Stopwatch.StartNew();
            string xmlBody = this.GetXmlBody();

            byte[] bytes = Encoding.UTF8.GetBytes(xmlBody);
            WindowsImpersonationContext windowsImpersonationContext = null;
            Exception ex = null;

            try
            {
                this.request             = (HttpWebRequest)WebRequest.Create(this.targetUri);
                this.request.Method      = "POST";
                this.request.ContentType = "text/xml";
                this.request.Headers.Add("X-AnchorMailbox", this.emailAddress.Address);
                if (this.credentialsForDiscovery == null)
                {
                    if (Testability.WebServiceCredentials == null)
                    {
                        windowsImpersonationContext = NetworkServiceImpersonator.Impersonate();
                        this.impersonating          = true;
                    }
                    this.credentialsForDiscovery = CredentialCache.DefaultCredentials;
                    this.request.Credentials     = this.credentialsForDiscovery;
                }
                else
                {
                    CredentialCache credentialCache = new CredentialCache();
                    credentialCache.Add(this.targetUri, "Basic", (NetworkCredential)this.credentialsForDiscovery);
                    this.request.Credentials     = credentialCache;
                    this.request.PreAuthenticate = true;
                }
                this.request.Timeout           = (int)this.timeout.TotalMilliseconds;
                this.request.UserAgent         = this.GetUserAgent();
                this.request.AllowAutoRedirect = false;
                this.request.ContentLength     = (long)bytes.Length;
                if (this.bypassProxy)
                {
                    this.request.Proxy = new WebProxy();
                }
                CertificateValidationManager.SetComponentId(this.request, Globals.CertificateValidationComponentId);
                using (Stream requestStream = this.request.GetRequestStream())
                {
                    requestStream.Write(bytes, 0, bytes.Length);
                }
                AutoDiscoverRequest.AutoDiscoverTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Sending request to AutoDiscover service, xml body: {1}", TraceContext.Get(), xmlBody);
                if (base.Aborted)
                {
                    this.request.Abort();
                }
                return(this.request.BeginGetResponse(new AsyncCallback(base.Complete), null));
            }
            catch (ProtocolViolationException ex2)
            {
                ex = ex2;
            }
            catch (SecurityException ex3)
            {
                ex = ex3;
            }
            catch (ArgumentException ex4)
            {
                ex = ex4;
            }
            catch (InvalidOperationException ex5)
            {
                ex = ex5;
            }
            catch (NotSupportedException ex6)
            {
                ex = ex6;
            }
            catch (XmlException ex7)
            {
                ex = ex7;
            }
            catch (XPathException ex8)
            {
                ex = ex8;
            }
            catch
            {
                throw;
            }
            finally
            {
                if (windowsImpersonationContext != null)
                {
                    windowsImpersonationContext.Dispose();
                    this.impersonating = false;
                }
            }
            if (ex != null)
            {
                this.HandleException(ex);
            }
            return(null);
        }