예제 #1
0
        // Token: 0x060011F7 RID: 4599 RVA: 0x0006CE70 File Offset: 0x0006B070
        private void CopyProxyResponse(HttpWebResponse response)
        {
            this.copyProxyAttempts++;
            this.proxyResponse       = response;
            this.proxyResponseStream = this.proxyResponse.GetResponseStream();
            bool flag = false;

            for (int i = 0; i < this.proxyResponse.Headers.Count; i++)
            {
                string text = this.proxyResponse.Headers.Keys[i];
                if (ProxyUtilities.ShouldCopyProxyResponseHeader(text))
                {
                    this.OriginalResponse.AddHeader(text, this.proxyResponse.Headers[text]);
                }
                if (string.Compare(text, "mailboxCrossSiteFailover", true, CultureInfo.InvariantCulture) == 0)
                {
                    flag = true;
                    Utilities.DeleteCookie(this.OriginalResponse, UserContextCookie.GetUserContextCookie(base.OwaContext).CookieName);
                }
            }
            if (!flag && Globals.OwaVDirType == OWAVDirType.OWA)
            {
                ProxyUtilities.UpdateProxyUserContextIdFromResponse(this.proxyResponse, base.OwaContext.UserContext);
            }
            ProxyUtilities.UpdateProxyClientDataCollectingCookieFromResponse(this.proxyResponse, this.OriginalResponse);
            this.OriginalResponse.StatusCode  = (int)this.proxyResponse.StatusCode;
            this.OriginalResponse.ContentType = this.proxyResponse.ContentType;
            if ("chunked".Equals(this.proxyResponse.Headers["Transfer-Encoding"], StringComparison.OrdinalIgnoreCase))
            {
                this.OriginalResponse.BufferOutput = false;
            }
            this.proxyStreamCopy = new ProxyStreamCopy(this.proxyResponseStream, this.OriginalResponseStream, StreamCopyMode.AsyncReadSyncWrite);
            this.proxyStreamCopy.BeginCopy(new AsyncCallback(this.CopyProxyResponseStreamCallback), this);
        }
 // Token: 0x0600120F RID: 4623 RVA: 0x0006DBB4 File Offset: 0x0006BDB4
 private void GetResponseCallback(IAsyncResult asyncResult)
 {
     lock (this)
     {
         if (!this.requestTimedOut)
         {
             try
             {
                 if (this.timeoutWaitHandle != null)
                 {
                     this.timeoutWaitHandle.Unregister(null);
                     this.timeoutWaitHandle = null;
                 }
                 this.proxyResponse = ProxyUtilities.EndGetResponse(this.proxyRequest, asyncResult, this.requestClock);
                 ProxyUtilities.UpdateProxyUserContextIdFromResponse(this.proxyResponse, this.owaContext.UserContext);
             }
             catch (Exception exception)
             {
                 this.asyncResult.CompleteRequest(false, exception);
                 return;
             }
             this.asyncResult.CompleteRequest(false);
         }
     }
 }
예제 #3
0
        // Token: 0x060011EF RID: 4591 RVA: 0x0006C750 File Offset: 0x0006A950
        private bool EnsureCasCompatibility(HttpWebResponse response, out ServerVersion secondCasVersion)
        {
            ExTraceGlobals.ProxyCallTracer.TraceDebug((long)this.GetHashCode(), "ProxyEventHandler.EnsureCasCompatibility");
            secondCasVersion = null;
            string versionString = response.Headers["X-OWA-Version"];

            secondCasVersion = ServerVersion.CreateFromVersionString(versionString);
            if (secondCasVersion == null)
            {
                throw new OwaInvalidOperationException(string.Format("The format of the header {0}is wrong", "X-OWA-ProxyVersion"));
            }
            int num = ServerVersion.Compare(Globals.LocalHostVersion, secondCasVersion);

            if (num == 0)
            {
                ExTraceGlobals.ProxyTracer.TraceDebug((long)this.GetHashCode(), "Both CAS servers are the same version");
                return(true);
            }
            if (num > 0)
            {
                ExTraceGlobals.ProxyTracer.TraceDebug((long)this.GetHashCode(), "Proxy CAS version is larger than second CAS version");
                if (ProxyUtilities.IsVersionFolderInProxy(secondCasVersion))
                {
                    ExTraceGlobals.ProxyTracer.TraceDebug((long)this.GetHashCode(), "Proxy CAS has the version folder corresponding to the second CAS version");
                    return(true);
                }
                ExTraceGlobals.ProxyTracer.TraceDebug((long)this.GetHashCode(), "Proxy doesn't have the version folder corresponding to the second CAS version");
            }
            return(false);
        }
예제 #4
0
 // Token: 0x0600124F RID: 4687 RVA: 0x0006FD17 File Offset: 0x0006DF17
 internal bool Parse()
 {
     this.isParsed = true;
     this.uri      = ProxyUtilities.TryCreateCasUri(this.uriString, this.needVdirValidation);
     if (this.uri == null)
     {
         return(false);
     }
     this.isValid = true;
     return(true);
 }
 // Token: 0x0600120E RID: 4622 RVA: 0x0006DB14 File Offset: 0x0006BD14
 private void CopyRequestStreamCallback(IAsyncResult result)
 {
     try
     {
         this.proxyStreamCopy.EndCopy(result);
         this.requestTimedOut = false;
         IAsyncResult asyncResult = ProxyUtilities.BeginGetResponse(this.proxyRequest, new AsyncCallback(this.GetResponseCallback), this, out this.requestClock);
         this.timeoutWaitHandle = ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(this.RequestTimeoutCallback), asyncResult, (long)this.owaContext.HttpContext.Server.ScriptTimeout * 1000L, true);
     }
     catch (Exception exception)
     {
         this.asyncResult.CompleteRequest(false, exception);
     }
 }
예제 #6
0
 // Token: 0x06001266 RID: 4710 RVA: 0x00070410 File Offset: 0x0006E610
 internal static IAsyncResult BeginGetResponse(HttpWebRequest request, AsyncCallback asyncCallback, object context, out Stopwatch requestClock)
 {
     if (Globals.ArePerfCountersEnabled)
     {
         long num = (long)request.Headers.ToByteArray().Length;
         if (request.ContentLength > 0L)
         {
             num += request.ContentLength;
         }
         OwaSingleCounters.ProxyRequestBytes.IncrementBy(num);
     }
     requestClock = Stopwatch.StartNew();
     ProxyUtilities.TraceProxyRequest(request);
     return(request.BeginGetResponse(asyncCallback, context));
 }
        private HttpWebRequest GetProxyRequest(int contentLength)
        {
            NetworkServiceImpersonator.Initialize();
            if (NetworkServiceImpersonator.Exception != null)
            {
                ExTraceGlobals.ProxyCallTracer.TraceError <LocalizedException>(0L, "Unable to impersonate network service to call EWS due exception {0}", NetworkServiceImpersonator.Exception);
                throw new AsyncExceptionWrapper(NetworkServiceImpersonator.Exception);
            }
            HttpWebRequest httpWebRequest = ProxyUtilities.CreateHttpWebRequestForProxying(base.OwaContext, this.proxyRequestUrl);

            httpWebRequest.Method          = "POST";
            httpWebRequest.ContentType     = this.HttpContext.Request.ContentType;
            httpWebRequest.ContentLength   = (long)contentLength;
            httpWebRequest.UserAgent       = "OwaProxy";
            httpWebRequest.PreAuthenticate = true;
            return(httpWebRequest);
        }
        // Token: 0x0600120B RID: 4619 RVA: 0x0006D974 File Offset: 0x0006BB74
        internal void BeginSend(OwaContext owaContext, HttpRequest originalRequest, string targetUrl, string proxyRequestBody, AsyncCallback callback, object extraData)
        {
            ExTraceGlobals.ProxyCallTracer.TraceDebug((long)this.GetHashCode(), "ProxyProtocolRequest.BeginSend");
            Uri uri = new UriBuilder(owaContext.SecondCasUri.Uri)
            {
                Path = targetUrl
            }.Uri;
            HttpWebRequest proxyRequestInstance = ProxyUtilities.GetProxyRequestInstance(originalRequest, owaContext, uri);

            proxyRequestInstance.ContentLength = (long)((proxyRequestBody != null) ? Encoding.UTF8.GetByteCount(proxyRequestBody) : 0);
            proxyRequestInstance.Method        = "POST";
            this.proxyRequest     = proxyRequestInstance;
            this.proxyRequestBody = proxyRequestBody;
            this.owaContext       = owaContext;
            this.asyncResult      = new OwaAsyncResult(callback, extraData);
            proxyRequestInstance.BeginGetRequestStream(new AsyncCallback(this.GetRequestStreamCallback), this);
        }
예제 #9
0
        internal void BeginSend(OwaContext owaContext, AsyncCallback callback, object extraData)
        {
            ExTraceGlobals.ProxyCallTracer.TraceDebug((long)this.GetHashCode(), "ProxyPingRequest.BeginSend");
            Uri uri = new UriBuilder(owaContext.SecondCasUri.Uri)
            {
                Path = OwaUrl.ProxyPing.GetExplicitUrl(owaContext)
            }.Uri;
            HttpWebRequest httpWebRequest = ProxyUtilities.CreateHttpWebRequestForProxying(owaContext, uri);

            httpWebRequest.Method    = "GET";
            httpWebRequest.UserAgent = "OwaProxy";
            this.request             = httpWebRequest;
            this.asyncResult         = new OwaAsyncResult(callback, extraData);
            this.requestTimedOut     = false;
            IAsyncResult asyncResult = ProxyUtilities.BeginGetResponse(this.request, new AsyncCallback(this.GetResponseCallback), this, out this.requestClock);

            this.timeoutWaitHandle = ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(this.RequestTimeoutCallback), asyncResult, (long)owaContext.HttpContext.Server.ScriptTimeout * 1000L, true);
        }
예제 #10
0
        // Token: 0x06001267 RID: 4711 RVA: 0x00070468 File Offset: 0x0006E668
        internal static HttpWebResponse EndGetResponse(HttpWebRequest request, IAsyncResult asyncResult, Stopwatch requestClock)
        {
            requestClock.Stop();
            long            elapsedMilliseconds = requestClock.ElapsedMilliseconds;
            HttpWebResponse result;

            try
            {
                HttpWebResponse httpWebResponse = (HttpWebResponse)request.EndGetResponse(asyncResult);
                ProxyUtilities.TraceProxyResponse(request, (int)httpWebResponse.StatusCode, elapsedMilliseconds);
                result = httpWebResponse;
            }
            catch (WebException exception)
            {
                ProxyUtilities.TraceFailedProxyRequest(request, exception, elapsedMilliseconds);
                throw;
            }
            return(result);
        }
예제 #11
0
        // Token: 0x06001202 RID: 4610 RVA: 0x0006D5E8 File Offset: 0x0006B7E8
        private void GetNextFailoverCas()
        {
            ExTraceGlobals.ProxyCallTracer.TraceDebug((long)this.GetHashCode(), "ProxyEventHandler.GetNextFailoverCas");
            bool flag = false;

            try
            {
                base.OwaContext.UserContext.Lock();
                flag = true;
                ProxyUriQueue proxyUriQueue = base.UserContext.ProxyUriQueue;
                if (proxyUriQueue.Head != base.OwaContext.SecondCasUri)
                {
                    base.OwaContext.SecondCasUri = proxyUriQueue.Head;
                }
                else
                {
                    ProxyUri proxyUri = proxyUriQueue.Pop();
                    if (!proxyUri.IsValid)
                    {
                        ProxyUtilities.ThrowMalformedCasUriException(base.OwaContext, proxyUri.ToString());
                    }
                    ProxyUtilities.EnsureProxyUrlSslPolicy(base.OwaContext, proxyUri);
                    base.OwaContext.SecondCasUri = proxyUri;
                    ExTraceGlobals.ProxyTracer.TraceDebug <ProxyUri>((long)this.GetHashCode(), "SecondCasUri = {0}", base.OwaContext.SecondCasUri);
                }
                this.proxyRequestUrl = new UriBuilder(this.proxyRequestUrl)
                {
                    Scheme = base.OwaContext.SecondCasUri.Uri.Scheme,
                    Host   = base.OwaContext.SecondCasUri.Uri.Host,
                    Port   = base.OwaContext.SecondCasUri.Uri.Port
                }.Uri;
                this.proxyLogonAttempts = 0;
            }
            finally
            {
                if (base.OwaContext.UserContext.LockedByCurrentThread() && flag)
                {
                    base.OwaContext.UserContext.Unlock();
                }
            }
        }
예제 #12
0
 // Token: 0x060011F1 RID: 4593 RVA: 0x0006C8E4 File Offset: 0x0006AAE4
 private void CopyOriginalRequestStreamCallback(IAsyncResult result)
 {
     try
     {
         this.proxyStreamCopy.EndCopy(result);
         this.copyingOriginalRequestComplete = true;
         this.requestTimedOut = false;
         IAsyncResult asyncResult = ProxyUtilities.BeginGetResponse(this.proxyRequest, new AsyncCallback(this.GetProxyResponseCallback), this, out this.requestClock);
         this.timeoutWaitHandle = ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(this.RequestTimeoutCallback), asyncResult, (long)this.HttpContext.Server.ScriptTimeout * 1000L, true);
     }
     catch (WebException webException)
     {
         if (!this.CheckAndHandleConnectionFailure(webException))
         {
             this.HandleWebExceptionDefault(webException);
         }
     }
     catch (Exception exception)
     {
         this.asyncResult.CompleteRequest(false, exception);
     }
 }
예제 #13
0
        // Token: 0x060011EB RID: 4587 RVA: 0x0006C3FC File Offset: 0x0006A5FC
        private void SendProxyRequest()
        {
            ExTraceGlobals.ProxyCallTracer.TraceDebug((long)this.GetHashCode(), "ProxyEventHandler.SendProxyRequest");
            if (base.OwaContext.SecondCasUri.ProxyPingResult == ProxyPingResult.Unknown)
            {
                this.SendProxyPingRequest();
                return;
            }
            HttpWebRequest proxyRequestInstance = ProxyUtilities.GetProxyRequestInstance(this.OriginalRequest, base.OwaContext, this.proxyRequestUrl);

            proxyRequestInstance.Method = ((base.Verb == OwaEventVerb.Post) ? "POST" : "GET");
            this.proxyRequest           = proxyRequestInstance;
            if (base.Verb == OwaEventVerb.Post)
            {
                this.proxyRequest.BeginGetRequestStream(new AsyncCallback(this.GetProxyRequestStreamCallback), this);
                return;
            }
            this.requestTimedOut = false;
            IAsyncResult asyncResult = ProxyUtilities.BeginGetResponse(this.proxyRequest, new AsyncCallback(this.GetProxyResponseCallback), this, out this.requestClock);

            this.timeoutWaitHandle = ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(this.RequestTimeoutCallback), asyncResult, (long)this.HttpContext.Server.ScriptTimeout * 1000L, true);
        }
예제 #14
0
 // Token: 0x060011F2 RID: 4594 RVA: 0x0006C9A8 File Offset: 0x0006ABA8
 private void GetProxyResponseCallback(IAsyncResult asyncResult)
 {
     ExTraceGlobals.ProxyCallTracer.TraceDebug((long)this.GetHashCode(), "ProxyEventHandler.GetProxyResponseCallback");
     lock (this)
     {
         if (!this.requestTimedOut)
         {
             try
             {
                 if (this.timeoutWaitHandle != null)
                 {
                     this.timeoutWaitHandle.Unregister(null);
                     this.timeoutWaitHandle = null;
                 }
                 HttpWebResponse response = ProxyUtilities.EndGetResponse(this.proxyRequest, asyncResult, this.requestClock);
                 this.CopyProxyResponse(response);
             }
             catch (WebException ex)
             {
                 if (!this.CheckAndHandleConnectionFailure(ex))
                 {
                     if (ex.Status == WebExceptionStatus.ProtocolError)
                     {
                         if (!this.CheckAndHandleWebException40X(ex))
                         {
                             HttpWebResponse httpWebResponse = (HttpWebResponse)ex.Response;
                             int             statusCode      = (int)httpWebResponse.StatusCode;
                             if (statusCode == 441)
                             {
                                 ExTraceGlobals.ProxyTracer.TraceDebug((long)this.GetHashCode(), "The proxy returned 441, this means we need to attempt to do a proxy logon");
                                 try
                                 {
                                     this.SendProxyLogonRequest();
                                     return;
                                 }
                                 catch (Exception exception)
                                 {
                                     this.asyncResult.CompleteRequest(false, exception);
                                     return;
                                 }
                             }
                             if (statusCode == 442)
                             {
                                 ExTraceGlobals.ProxyTracer.TraceDebug((long)this.GetHashCode(), "The proxy returned 442, this means the user's language or timezone are invalid");
                                 this.OriginalResponse.Redirect(OwaUrl.LanguagePage.GetExplicitUrl(this.OriginalRequest), false);
                                 base.OwaContext.HttpContext.ApplicationInstance.CompleteRequest();
                                 this.asyncResult.CompleteRequest(false);
                             }
                             else
                             {
                                 this.HandleProtocolExceptionDefault(ex);
                             }
                         }
                     }
                     else
                     {
                         this.HandleWebExceptionDefault(ex);
                     }
                 }
             }
             catch (Exception exception2)
             {
                 this.asyncResult.CompleteRequest(false, exception2);
             }
         }
     }
 }
예제 #15
0
        // Token: 0x06001262 RID: 4706 RVA: 0x0006FFC8 File Offset: 0x0006E1C8
        internal static HttpWebRequest GetProxyRequestInstance(HttpRequest originalRequest, OwaContext owaContext, Uri requestUri)
        {
            string         name           = "X-LogonType";
            string         value          = "Public";
            HttpWebRequest httpWebRequest = ProxyUtilities.CreateHttpWebRequestForProxying(owaContext, requestUri);

            for (int i = 0; i < originalRequest.Headers.Count; i++)
            {
                string text = originalRequest.Headers.Keys[i];
                if (ProxyUtilities.ShouldCopyProxyRequestHeader(text))
                {
                    httpWebRequest.Headers[text] = originalRequest.Headers[text];
                }
            }
            httpWebRequest.UserAgent = originalRequest.UserAgent;
            string text2 = originalRequest.Headers["referer"];

            if (text2 != null)
            {
                httpWebRequest.Referer = text2;
            }
            text2 = originalRequest.Headers["accept"];
            if (text2 != null)
            {
                httpWebRequest.Accept = text2;
            }
            text2 = originalRequest.Headers["transfer-encoding"];
            if (text2 != null)
            {
                httpWebRequest.TransferEncoding = text2;
            }
            httpWebRequest.ContentLength = (long)originalRequest.ContentLength;
            httpWebRequest.ContentType   = originalRequest.ContentType;
            httpWebRequest.UserAgent     = originalRequest.UserAgent;
            if (httpWebRequest.Headers[name] == null && owaContext.SessionContext != null && owaContext.SessionContext.IsPublicRequest(originalRequest))
            {
                httpWebRequest.Headers.Add(name, value);
            }
            httpWebRequest.Headers["X-OWA-ProxyUri"]     = owaContext.LocalHostName;
            httpWebRequest.Headers["X-OWA-ProxyVersion"] = Globals.ApplicationVersion;
            if (Globals.OwaVDirType == OWAVDirType.OWA)
            {
                httpWebRequest.Headers["X-OWA-ProxySid"] = owaContext.LogonIdentity.UserSid.ToString();
            }
            httpWebRequest.Headers["X-OWA-ProxyCanary"] = Utilities.GetCurrentCanary(owaContext.SessionContext);
            if (owaContext.RequestType == OwaRequestType.WebPart)
            {
                httpWebRequest.Headers["X-OWA-ProxyWebPart"] = "1";
            }
            if (owaContext.TryGetUserContext() != null && owaContext.UserContext.ProxyUserContextCookie != null)
            {
                ExTraceGlobals.ProxyDataTracer.TraceDebug <UserContextCookie>(0L, "Setting proxy user context cookie: {0}", owaContext.UserContext.ProxyUserContextCookie);
                Cookie netCookie = owaContext.UserContext.ProxyUserContextCookie.NetCookie;
                ProxyUtilities.AddCookieToProxyRequest(httpWebRequest, netCookie, requestUri.Host);
            }
            else
            {
                ExTraceGlobals.ProxyDataTracer.TraceDebug(0L, "No user context cookie used for the proxy request");
            }
            foreach (string name2 in ProxyUtilities.ProxyAllowedCookies)
            {
                if (owaContext.HttpContext.Request.Cookies[name2] != null)
                {
                    Cookie cookie = new Cookie(name2, owaContext.HttpContext.Request.Cookies[name2].Value);
                    ProxyUtilities.AddCookieToProxyRequest(httpWebRequest, cookie, requestUri.Host);
                }
            }
            return(httpWebRequest);
        }