예제 #1
0
 protected override void OnBeginRequestInternal(HttpApplication httpApplication)
 {
     this.basicAuthString = null;
     this.destinationUrl  = null;
     this.userName        = null;
     this.cadataKeyString = null;
     this.cadataIVString  = null;
     this.symKey          = null;
     this.symIV           = null;
     this.flags           = 0;
     this.password        = null;
     httpApplication.Context.Items["AuthType"] = "FBA";
     if (!this.HandleFbaAuthFormPost(httpApplication))
     {
         try
         {
             this.ParseCadataCookies(httpApplication);
         }
         catch (MissingSslCertificateException)
         {
             AspNetHelper.TransferToErrorPage(httpApplication.Context, ErrorFE.FEErrorCodes.SSLCertificateProblem);
         }
     }
     base.OnBeginRequestInternal(httpApplication);
 }
예제 #2
0
 protected virtual void OnBeginRequestInternal(HttpApplication httpApplication)
 {
     if (HttpProxyGlobals.OnlyProxySecureConnections && !httpApplication.Request.IsSecureConnection)
     {
         AspNetHelper.TerminateRequestWithSslRequiredResponse(httpApplication);
     }
 }
예제 #3
0
        // Token: 0x060005D2 RID: 1490 RVA: 0x000205F8 File Offset: 0x0001E7F8
        private string GetCrossPremiseRedirectUrl(string domainName, string externalDirectoryOrgId, string externalEmailAddress)
        {
            NameValueCollection nameValueCollection = new NameValueCollection();
            string value = UrlUtilities.IsConsumerRequestForO365(base.HttpContext) ? OwaProxyRequestHandler.SilentRedirection : OwaProxyRequestHandler.ManualRedirection;

            nameValueCollection.Add("redirectType", value);
            nameValueCollection.Add("extDomain", domainName);
            nameValueCollection.Add("extDirOrgId", externalDirectoryOrgId);
            if (CafeConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).AddExternalEmailAddressToRedirectURL.Enabled)
            {
                nameValueCollection.Add("extEmail", externalEmailAddress);
            }
            return(AspNetHelper.GetCafeErrorPageRedirectUrl(base.HttpContext, nameValueCollection));
        }
예제 #4
0
        private void OnBeginRequest(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                LatencyTracker latencyTracker = new LatencyTracker();
                latencyTracker.StartTracking(LatencyTrackerKey.ProxyModuleLatency, false);
                AspNetHelper.AddTimestampHeaderIfNecessary(httpContext.Request.Headers, "X-FrontEnd-Begin");
                if (Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.TraceDebug <string, Uri, int>((long)this.GetHashCode(), "[ProxyModule::OnBeginRequest]: Method {0}; Url {1}; Context {2};", httpContext.Request.HttpMethod, httpContext.Request.Url, httpContext.GetHashCode());
                }
                if (HealthCheckResponder.Instance.IsHealthCheckRequest(httpContext))
                {
                    HealthCheckResponder.Instance.CheckHealthStateAndRespond(httpContext);
                    return;
                }
                RequestDetailsLogger requestDetailsLogger = RequestDetailsLoggerBase <RequestDetailsLogger> .InitializeRequestLogger();
                requestDetailsLogger.LogCurrentTime("BeginRequest");
                httpContext.Items[Constants.TraceContextKey] = httpContext.GetHashCode();
                httpContext.Items[Constants.LatencyTrackerContextKeyName] = latencyTracker;
                requestDetailsLogger.ActivityScope.UpdateFromMessage(httpContext.Request);
                requestDetailsLogger.ActivityScope.SerializeTo(httpContext.Response);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SetCurrent(httpContext, requestDetailsLogger);
                httpContext.Items[typeof(ActivityScope)] = requestDetailsLogger.ActivityScope;
                httpContext.Items[Constants.RequestIdHttpContextKeyName] = requestDetailsLogger.ActivityScope.ActivityId;
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, HttpProxyMetadata.Protocol, HttpProxyGlobals.ProtocolType);
                requestDetailsLogger.SafeLogUriData(httpContext.Request.Url);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, ServiceCommonMetadata.HttpMethod, httpContext.Request.HttpMethod);
                string requestCorrelationId = AspNetHelper.GetRequestCorrelationId(httpContext);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestDetailsLogger, "CorrelationID", requestCorrelationId);
                httpContext.Response.AppendToLog(Constants.CorrelationIdKeyForIISLogs + requestCorrelationId + ";");
                string cookieValueAndSetIfNull = ClientIdCookie.GetCookieValueAndSetIfNull(httpContext);
                httpContext.Response.AppendToLog(string.Format("&{0}={1}", "ClientId", cookieValueAndSetIfNull));
                UrlUtilities.SaveOriginalRequestHostSchemePortToContext(httpContext);
                try
                {
                    this.OnBeginRequestInternal(httpApplication);
                }
                catch (Exception ex)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericError(requestDetailsLogger, "OnBeginRequestInternal", ex.ToString());
                    requestDetailsLogger.AsyncCommit(false);
                    throw;
                }
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
        // Token: 0x060005A7 RID: 1447 RVA: 0x0001F708 File Offset: 0x0001D908
        private string GetCrossSiteRedirectUrl(string targetSiteDistinguishedName, string path, string query)
        {
            NameValueCollection nameValueCollection = new NameValueCollection();

            nameValueCollection.Add("redirectType", 0.ToString());
            nameValueCollection.Add("targetSiteDistinguishedName", targetSiteDistinguishedName);
            if (!string.IsNullOrEmpty(path))
            {
                nameValueCollection.Add("path", path);
            }
            if (!string.IsNullOrEmpty(query))
            {
                nameValueCollection.Add("query", query);
            }
            return(AspNetHelper.GetCafeErrorPageRedirectUrl(base.HttpContext, nameValueCollection));
        }
예제 #6
0
        // Token: 0x060005FA RID: 1530 RVA: 0x00021B74 File Offset: 0x0001FD74
        private void OnPreSendRequestHeaders(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            CheckpointTracker.GetOrCreate(httpContext.Items).Add(FrontEndHttpProxyCheckpoints.ProxyModulePreSendRequestHeaders);
            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                if (httpContext != null && httpContext.Response != null && httpContext.Response.Headers != null)
                {
                    AspNetHelper.AddTimestampHeaderIfNecessary(httpContext.Response.Headers, "X-FrontEnd-End");
                    RequestDetailsLogger current = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext);
                    if (current != null && !current.IsDisposed)
                    {
                        this.SetResponseHeaders(current, httpContext);
                    }
                    if (Extensions.IsProbeRequest(Extensions.GetHttpRequestBase(httpContext.Request)) && !RequestFailureContext.IsSetInResponse(SharedHttpContextWrapper.GetWrapper(httpContext).Response))
                    {
                        RequestFailureContext requestFailureContext = null;
                        if (httpContext.Items.Contains(RequestFailureContext.HttpContextKeyName))
                        {
                            requestFailureContext = (RequestFailureContext)httpContext.Items[RequestFailureContext.HttpContextKeyName];
                        }
                        else if (httpContext.Response.StatusCode >= 400 && httpContext.Response.StatusCode < 600)
                        {
                            LiveIdAuthResult?liveIdAuthResult = null;
                            LiveIdAuthResult value;
                            if (httpContext.Items.Contains("LiveIdBasicAuthResult") && Enum.TryParse <LiveIdAuthResult>((string)httpContext.Items["LiveIdBasicAuthResult"], true, out value))
                            {
                                liveIdAuthResult = new LiveIdAuthResult?(value);
                            }
                            requestFailureContext = new RequestFailureContext(1, httpContext.Response.StatusCode, httpContext.Response.StatusDescription, string.Empty, null, null, liveIdAuthResult);
                        }
                        if (requestFailureContext != null)
                        {
                            requestFailureContext.UpdateResponse(SharedHttpContextWrapper.GetWrapper(httpContext).Response);
                        }
                    }
                    ProxyRequestHandler proxyRequestHandler = httpContext.CurrentHandler as ProxyRequestHandler;
                    if (proxyRequestHandler != null)
                    {
                        proxyRequestHandler.ResponseHeadersSent = true;
                    }
                }
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
예제 #7
0
 public static string GetClientPortAsProxyHeader(HttpContext httpContext)
 {
     return(AspNetHelper.GetClientPortAsProxyHeader(httpContext));
 }
예제 #8
0
 public static string GetClientIpAsProxyHeader(HttpRequest httpRequest)
 {
     return(AspNetHelper.GetClientIpAsProxyHeader(httpRequest));
 }
        private void HandleFbaFormPost(BackEndServer backEndServer)
        {
            HttpContext      httpContext            = base.HttpContext;
            HttpResponse     response               = httpContext.Response;
            Uri              uri                    = null;
            string           text                   = httpContext.Items["destination"] as string;
            bool             flag                   = false;
            bool             flag2                  = false;
            bool             flag3                  = true;
            string           fqdn                   = backEndServer.Fqdn;
            int              version                = backEndServer.Version;
            OwaServerVersion owaServerVersion       = null;
            bool             flag4                  = false;
            ServiceTopology  currentServiceTopology = ServiceTopology.GetCurrentServiceTopology("f:\\15.00.1497\\sources\\dev\\cafe\\src\\HttpProxy\\RequestHandlers\\FbaFormPostProxyRequestHandler.cs", "HandleFbaFormPost", 780);
            Site             site                   = currentServiceTopology.GetSite(fqdn, "f:\\15.00.1497\\sources\\dev\\cafe\\src\\HttpProxy\\RequestHandlers\\FbaFormPostProxyRequestHandler.cs", "HandleFbaFormPost", 781);

            if (site != null && !site.Equals(HttpProxyGlobals.LocalSite.Member))
            {
                flag3 = false;
            }
            if (!FbaFormPostProxyRequestHandler.DisableSSORedirects)
            {
                owaServerVersion = OwaServerVersion.CreateFromVersionNumber(version);
                if (UrlUtilities.IsEcpUrl(text) && owaServerVersion.Major < (int)ExchangeObjectVersion.Exchange2010.ExchangeBuild.Major)
                {
                    flag  = false;
                    flag2 = false;
                }
                else if (!flag3 && !UserAgentParser.IsMonitoringRequest(base.ClientRequest.UserAgent))
                {
                    if (owaServerVersion.Major >= (int)ExchangeObjectVersion.Exchange2007.ExchangeBuild.Major)
                    {
                        FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause legacyRedirectFailureCause = FbaFormPostProxyRequestHandler.NeedCrossSiteRedirect(backEndServer, site, HttpProxyGlobals.LocalSite.Member, owaServerVersion, UrlUtilities.IsEcpUrl(text), out uri, out flag4);
                        string authority = base.ClientRequest.Url.Authority;
                        string b         = (uri == null) ? string.Empty : uri.Authority;
                        flag2 = (legacyRedirectFailureCause != FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause.NoCasFound && !string.Equals(authority, b, StringComparison.OrdinalIgnoreCase) && (legacyRedirectFailureCause != FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause.None || uri != null));
                        if (uri == null && owaServerVersion.Major == (int)ExchangeObjectVersion.Exchange2007.ExchangeBuild.Major)
                        {
                            flag = (FbaFormPostProxyRequestHandler.NeedOnSiteLegacyRedirect(backEndServer, null, HttpProxyGlobals.LocalSite.Member, owaServerVersion, out uri, out flag4) != FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause.None || uri != null);
                        }
                    }
                }
                else
                {
                    flag = (FbaFormPostProxyRequestHandler.NeedOnSiteLegacyRedirect(backEndServer, site, HttpProxyGlobals.LocalSite.Member, owaServerVersion, out uri, out flag4) != FbaFormPostProxyRequestHandler.LegacyRedirectFailureCause.None || uri != null);
                }
            }
            if (flag2 || flag)
            {
                if (uri != null)
                {
                    string authority2 = base.ClientRequest.Url.Authority;
                    string authority3 = uri.Authority;
                    if (string.Compare(authority2, authority3, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        throw new HttpException(403, "Redirect loop detected");
                    }
                }
                using (SecureNameValueCollection secureNameValueCollection = new SecureNameValueCollection())
                {
                    int num = (int)base.HttpContext.Items["flags"];
                    secureNameValueCollection.AddUnsecureNameValue("destination", base.HttpContext.Items["destination"] as string);
                    secureNameValueCollection.AddUnsecureNameValue("username", base.HttpContext.Items["username"] as string);
                    secureNameValueCollection.AddUnsecureNameValue("flags", num.ToString(CultureInfo.InvariantCulture));
                    using (SecureString secureString = base.HttpContext.Items["password"] as SecureString)
                    {
                        secureNameValueCollection.AddSecureNameValue("password", secureString);
                        if (flag)
                        {
                            if (uri == null)
                            {
                                AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoLegacyCAS);
                            }
                            else if (flag4)
                            {
                                if (uri.Scheme == Uri.UriSchemeHttps)
                                {
                                    ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - SSO redirecting to {0}", uri.ToString());
                                    this.RedirectUsingSSOFBA(secureNameValueCollection, uri, response, owaServerVersion.Major);
                                    response.End();
                                }
                                else
                                {
                                    AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoFbaSSL);
                                }
                            }
                            else
                            {
                                ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - redirecting to {0}", uri.ToString());
                                base.PfdTracer.TraceRedirect("FbaAuth", uri.ToString());
                                response.Redirect(FbaFormPostProxyRequestHandler.CheckRedirectUrlForNewline(uri.ToString()));
                            }
                        }
                        else if (flag2)
                        {
                            if (uri == null)
                            {
                                AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoLegacyCAS);
                            }
                            else
                            {
                                Uri uri2 = uri;
                                if (this.explicitLogonUser != null)
                                {
                                    uri2 = FbaFormPostProxyRequestHandler.AppendSmtpAddressToUrl(uri, this.explicitLogonUser);
                                }
                                if (flag4)
                                {
                                    if (uri.Scheme == Uri.UriSchemeHttps)
                                    {
                                        ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - SSO redirecting to {0}", uri.ToString());
                                        this.RedirectUsingSSOFBA(secureNameValueCollection, uri, response, owaServerVersion.Major);
                                        response.End();
                                    }
                                    else
                                    {
                                        AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoFbaSSL);
                                    }
                                }
                                else
                                {
                                    ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - redirecting to {0}", uri2.ToString());
                                    base.PfdTracer.TraceRedirect("FbaAuth", uri2.ToString());
                                    response.Redirect(FbaFormPostProxyRequestHandler.CheckRedirectUrlForNewline(uri2.ToString()));
                                }
                            }
                        }
                    }
                    return;
                }
            }
            try
            {
                FbaModule.SetCadataCookies(base.HttpApplication);
            }
            catch (MissingSslCertificateException)
            {
                AspNetHelper.TransferToErrorPage(httpContext, ErrorFE.FEErrorCodes.NoFbaSSL);
            }
            ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "FbaFormPostProxyRequestHandler - redirecting to {0}", text);
            base.PfdTracer.TraceRedirect("FbaAuth", text);
            response.Redirect(FbaFormPostProxyRequestHandler.CheckRedirectUrlForNewline(text), false);
        }
예제 #10
0
        private bool HandleFbaAuthFormPost(HttpApplication httpApplication)
        {
            HttpContext  context  = httpApplication.Context;
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            if (request.GetHttpMethod() != HttpMethod.Post)
            {
                return(false);
            }
            string strB = request.Url.Segments[request.Url.Segments.Length - 1];

            if (string.Compare("auth.owa", strB, StringComparison.OrdinalIgnoreCase) != 0 && string.Compare("owaauth.dll", strB, StringComparison.OrdinalIgnoreCase) != 0)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(request.ContentType))
            {
                request.ContentType = "application/x-www-form-urlencoded";
            }
            SecureHtmlFormReader secureHtmlFormReader = new SecureHtmlFormReader(request);

            secureHtmlFormReader.AddSensitiveInputName("password");
            SecureNameValueCollection secureNameValueCollection = null;

            try
            {
                if (!secureHtmlFormReader.TryReadSecureFormData(out secureNameValueCollection))
                {
                    AspNetHelper.EndResponse(context, HttpStatusCode.BadRequest);
                }
                string       text         = null;
                string       text2        = null;
                SecureString secureString = null;
                string       text3        = null;
                secureNameValueCollection.TryGetUnsecureValue("username", out text2);
                secureNameValueCollection.TryGetSecureValue("password", out secureString);
                secureNameValueCollection.TryGetUnsecureValue("destination", out text);
                secureNameValueCollection.TryGetUnsecureValue("flags", out text3);
                if (text == null || text2 == null || secureString == null || text3 == null || !this.CheckPostDestination(text, context.Request))
                {
                    AspNetHelper.EndResponse(context, HttpStatusCode.BadRequest);
                }
                this.password       = secureString.Copy();
                this.userName       = text2;
                this.destinationUrl = text;
                int num;
                if (int.TryParse(text3, NumberStyles.Integer, CultureInfo.InvariantCulture, out num))
                {
                    this.flags = num;
                }
                else
                {
                    this.flags = 0;
                }
                text2 += ":";
                Encoding @default     = Encoding.Default;
                int      maxByteCount = @default.GetMaxByteCount(text2.Length + secureString.Length);
                using (SecureArray <byte> secureArray = new SecureArray <byte>(maxByteCount))
                {
                    int num2 = @default.GetBytes(text2, 0, text2.Length, secureArray.ArrayValue, 0);
                    using (SecureArray <char> secureArray2 = secureString.ConvertToSecureCharArray())
                    {
                        num2 += @default.GetBytes(secureArray2.ArrayValue, 0, secureArray2.Length(), secureArray.ArrayValue, num2);
                        this.basicAuthString             = "Basic " + Convert.ToBase64String(secureArray.ArrayValue, 0, num2);
                        request.Headers["Authorization"] = this.basicAuthString;
                    }
                }
            }
            finally
            {
                if (secureNameValueCollection != null)
                {
                    secureNameValueCollection.Dispose();
                }
            }
            ExTraceGlobals.VerboseTracer.TraceDebug <Uri>(0L, "HandleFbaAuthFormPost - {0}", request.Url);
            return(true);
        }