Exemple #1
0
        public static void UpdateRequestHeaders(HttpContext httpContext)
        {
            ArgumentValidator.ThrowIfNull("httpContext", httpContext);
            string fullRawUrl = httpContext.Request.GetFullRawUrl();

            try
            {
                httpContext.Request.Headers[Constants.MsExchProxyUri] = fullRawUrl;
            }
            catch (ArgumentException)
            {
                httpContext.Request.Headers[Constants.MsExchProxyUri] = Uri.EscapeUriString(fullRawUrl);
            }
            httpContext.Request.Headers[Constants.XIsFromCafe]                 = Constants.IsFromCafeHeaderValue;
            httpContext.Request.Headers[Constants.XSourceCafeServer]           = HttpProxyGlobals.LocalMachineFqdn.Member;
            httpContext.Request.Headers[CafeHelper.CafeProxyHandler]           = CafeHelper.NativeHttpProxy;
            httpContext.Request.Headers[Constants.OriginatingClientIpHeader]   = AspNetHelper.GetClientIpAsProxyHeader(httpContext.Request);
            httpContext.Request.Headers[Constants.OriginatingClientPortHeader] = AspNetHelper.GetClientPortAsProxyHeader(httpContext);
            string value;

            if (HttpProxyRegistry.AreGccStoredSecretKeysValid.Member && (GccUtils.TryGetGccProxyInfo(httpContext, out value) || GccUtils.TryCreateGccProxyInfo(httpContext, out value)) && !string.IsNullOrEmpty(value))
            {
                httpContext.Request.Headers.Add("X-GCC-PROXYINFO", value);
            }
            string value2 = httpContext.Items["WLID-MemberName"] as string;

            if (!string.IsNullOrEmpty(value2))
            {
                httpContext.Request.Headers[Constants.WLIDMemberNameHeaderName] = value2;
                httpContext.Request.Headers[Constants.LiveIdMemberName]         = value2;
            }
            string text = httpContext.Request.Url.PathAndQuery;

            if (HttpProxyGlobals.ProtocolType == ProtocolType.RpcHttp)
            {
                RpcHttpQueryString rpcHttpQueryString = new RpcHttpQueryString(httpContext.Request.Url.Query);
                if (!string.IsNullOrEmpty(rpcHttpQueryString.RcaServer))
                {
                    httpContext.Request.Headers[WellKnownHeader.RpcHttpProxyServerTarget] = rpcHttpQueryString.RcaServer;
                }
            }
            else if (HttpProxyGlobals.ProtocolType == ProtocolType.Ews)
            {
                bool   selectedNodeIsLast;
                string explicitLogonNode = ProtocolHelper.GetExplicitLogonNode(httpContext.Request.ApplicationPath, httpContext.Request.FilePath, ExplicitLogonNode.Second, out selectedNodeIsLast);
                string text2;
                if (ProtocolHelper.TryGetValidNormalizedExplicitLogonAddress(explicitLogonNode, selectedNodeIsLast, out text2))
                {
                    Uri clientUrlForProxy = ProtocolHelper.GetClientUrlForProxy(httpContext.Request.Url, explicitLogonNode);
                    text = clientUrlForProxy.PathAndQuery;
                }
            }
            else if (HttpProxyGlobals.ProtocolType == ProtocolType.Eas)
            {
                text = text.Replace("Microsoft-Server-ActiveSync", "Microsoft-Server-ActiveSync/Proxy");
            }
            httpContext.Request.ServerVariables["X-ProxyTargetUrlAbsPath"] = text;
        }
Exemple #2
0
        IRoutingKey[] IAddressFinder.Find(AddressFinderSource source, IAddressFinderDiagnostics diagnostics)
        {
            AddressFinderHelper.ThrowIfNull(source, diagnostics);
            if (string.IsNullOrEmpty(source.Url.Query))
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            RpcHttpQueryString rpcHttpQueryString = new RpcHttpQueryString(source.Url.Query);

            if (!SmtpAddress.IsValidSmtpAddress(rpcHttpQueryString.RcaServer))
            {
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            Guid   guid = Guid.Empty;
            string text = string.Empty;

            try
            {
                SmtpAddress smtpAddress = new SmtpAddress(rpcHttpQueryString.RcaServer);
                guid = new Guid(smtpAddress.Local);
                text = smtpAddress.Domain;
            }
            catch (FormatException arg)
            {
                ExTraceGlobals.VerboseTracer.TraceDebug <string, FormatException>(0L, "[RpcHttpAddressFinder::Find]: Caught exception: Reason {0}; Exception {1}.", string.Format("Invalid mailboxGuid {0}", guid), arg);
                return(AddressFinderHelper.EmptyRoutingKeyArray);
            }
            string text2 = "MailboxGuidWithDomain";

            if (!text.Contains(".") && !source.Items.IsNullOrEmpty())
            {
                string text3 = source.Items["WLID-MemberName"] as string;
                if (!string.IsNullOrEmpty(text3))
                {
                    SmtpAddress smtpAddress2 = new SmtpAddress(text3);
                    string      domain       = smtpAddress2.Domain;
                    if (domain != null && !string.Equals(domain, text, StringComparison.OrdinalIgnoreCase))
                    {
                        ExTraceGlobals.BriefTracer.TraceError <string, string>((long)this.GetHashCode(), "[RpcHttpAddressFinder::Find]: Fixing up invalid domain name from client: {0} to {1}", text, domain);
                        text   = domain;
                        text2 += "-ChangedToUserDomain";
                    }
                }
            }
            IRoutingKey routingKey = new MailboxGuidRoutingKey(guid, text);

            diagnostics.AddRoutingkey(routingKey, text2);
            return(AddressFinderHelper.GetRoutingKeyArray(new IRoutingKey[]
            {
                routingKey
            }));
        }
        // Token: 0x0600070E RID: 1806 RVA: 0x000298E4 File Offset: 0x00027AE4
        protected override Uri GetTargetBackEndServerUrl()
        {
            UriBuilder uriBuilder = new UriBuilder(base.GetTargetBackEndServerUrl());

            if (this.updateRpcServer)
            {
                RpcHttpQueryString rpcHttpQueryString = new RpcHttpQueryString(uriBuilder.Query);
                if (string.IsNullOrEmpty(rpcHttpQueryString.RcaServerPort))
                {
                    uriBuilder.Query = uriBuilder.Host + rpcHttpQueryString.AdditionalParameters;
                }
                else
                {
                    uriBuilder.Query = uriBuilder.Host + ":" + rpcHttpQueryString.RcaServerPort + rpcHttpQueryString.AdditionalParameters;
                }
            }
            return(uriBuilder.Uri);
        }
        // Token: 0x0600070D RID: 1805 RVA: 0x000296EC File Offset: 0x000278EC
        protected override AnchorMailbox ResolveAnchorMailbox()
        {
            UriBuilder uriBuilder = new UriBuilder(base.ClientRequest.Url);

            if (string.IsNullOrEmpty(base.ClientRequest.Url.Query))
            {
                throw new HttpProxyException(HttpStatusCode.NotFound, 3001, "No proxy destination is specified!");
            }
            RpcHttpQueryString rpcHttpQueryString = new RpcHttpQueryString(uriBuilder.Query);

            this.rpcServerTarget = rpcHttpQueryString.RcaServer;
            if (SmtpAddress.IsValidSmtpAddress(this.rpcServerTarget))
            {
                string text;
                HttpContextItemParser.TryGetLiveIdMemberName(base.HttpContext.Items, ref text);
                Guid   guid;
                string domain;
                string text2;
                if (RequestQueryStringParser.TryGetMailboxGuid(this.rpcServerTarget, text, ref guid, ref domain, ref text2))
                {
                    MailboxGuidAnchorMailbox result;
                    if (!string.IsNullOrEmpty(text2))
                    {
                        this.rpcServerTarget = ExchangeRpcClientAccess.CreatePersonalizedServer(guid, text2);
                        base.Logger.AppendString(3, "MailboxGuidWithDomain-ChangedToUserDomain");
                        result = new MailboxGuidAnchorMailbox(guid, text2, this);
                    }
                    else
                    {
                        base.Logger.AppendString(3, "MailboxGuidWithDomain");
                        result = new MailboxGuidAnchorMailbox(guid, domain, this);
                    }
                    this.updateRpcServer = true;
                    return(result);
                }
                return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "InvalidFormat"));
            }
            else
            {
                ProxyDestination proxyDestination;
                if (RpcHttpProxyRules.Instance.TryGetProxyDestination(this.rpcServerTarget, out proxyDestination))
                {
                    string text3 = proxyDestination.GetHostName(this.GetKeyForCasAffinity());
                    if (proxyDestination.IsDynamicTarget)
                    {
                        try
                        {
                            text3 = DownLevelServerManager.Instance.GetDownLevelClientAccessServerWithPreferredServer <RpcHttpService>(new ServerInfoAnchorMailbox(text3, this), text3, 1, base.Logger, proxyDestination.Version).Fqdn;
                        }
                        catch (NoAvailableDownLevelBackEndException)
                        {
                            throw new HttpProxyException(HttpStatusCode.NotFound, 3001, string.Format("Cannot find a healthy E12 or E14 CAS to proxy to: {0}", this.rpcServerTarget));
                        }
                    }
                    uriBuilder.Host   = text3;
                    uriBuilder.Port   = proxyDestination.Port;
                    uriBuilder.Scheme = Uri.UriSchemeHttps;
                    base.Logger.Set(3, "RpcHttpProxyRules");
                    this.updateRpcServer = false;
                    return(new UrlAnchorMailbox(uriBuilder.Uri, this));
                }
                return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "UnknownServerName"));
            }
        }
Exemple #5
0
        protected override AnchorMailbox ResolveAnchorMailbox()
        {
            UriBuilder uriBuilder = new UriBuilder(base.ClientRequest.Url);

            if (string.IsNullOrEmpty(base.ClientRequest.Url.Query))
            {
                throw new HttpProxyException(HttpStatusCode.NotFound, HttpProxySubErrorCode.EndpointNotFound, "No proxy destination is specified!");
            }
            RpcHttpQueryString rpcHttpQueryString = new RpcHttpQueryString(uriBuilder.Query);

            this.rpcServerTarget = rpcHttpQueryString.RcaServer;
            if (SmtpAddress.IsValidSmtpAddress(this.rpcServerTarget))
            {
                Guid   mailboxGuid = Guid.Empty;
                string text        = string.Empty;
                try
                {
                    SmtpAddress smtpAddress = new SmtpAddress(this.rpcServerTarget);
                    mailboxGuid = new Guid(smtpAddress.Local);
                    text        = smtpAddress.Domain;
                }
                catch (FormatException)
                {
                    return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "InvalidFormat"));
                }
                base.Logger.Set(HttpProxyMetadata.RoutingHint, "MailboxGuidWithDomain");
                if (!text.Contains("."))
                {
                    string text2 = base.HttpContext.Items[Constants.WLIDMemberName] as string;
                    if (!string.IsNullOrEmpty(text2))
                    {
                        SmtpAddress smtpAddress2 = new SmtpAddress(text2);
                        string      domain       = smtpAddress2.Domain;
                        if (domain != null && !string.Equals(domain, text, StringComparison.OrdinalIgnoreCase))
                        {
                            ExTraceGlobals.BriefTracer.TraceError((long)this.GetHashCode(), "[RpcHttpProxyRequestHandler::ResolveAnchorMailbox]: Fixing up invalid domain name from client: {0} to {1}; Context {2}; State {3}", new object[]
                            {
                                text,
                                domain,
                                base.TraceContext,
                                base.State
                            });
                            text = domain;
                            this.rpcServerTarget = ExchangeRpcClientAccess.CreatePersonalizedServer(mailboxGuid, text);
                            base.Logger.AppendString(HttpProxyMetadata.RoutingHint, "-ChangedToUserDomain");
                        }
                    }
                }
                this.updateRpcServer = true;
                return(new MailboxGuidAnchorMailbox(mailboxGuid, text, this));
            }
            ProxyDestination proxyDestination;

            if (this.proxyRules.TryGetProxyDestination(this.rpcServerTarget, out proxyDestination))
            {
                string text3 = proxyDestination.GetHostName(this.GetKeyForCasAffinity());
                if (proxyDestination.IsDynamicTarget)
                {
                    try
                    {
                        text3 = DownLevelServerManager.Instance.GetDownLevelClientAccessServerWithPreferredServer <RpcHttpService>(new ServerInfoAnchorMailbox(text3, this), text3, ClientAccessType.External, base.Logger, proxyDestination.Version).Fqdn;
                    }
                    catch (NoAvailableDownLevelBackEndException)
                    {
                        throw new HttpProxyException(HttpStatusCode.NotFound, HttpProxySubErrorCode.EndpointNotFound, string.Format("Cannot find a healthy E12 or E14 CAS to proxy to: {0}", this.rpcServerTarget));
                    }
                }
                uriBuilder.Host   = text3;
                uriBuilder.Port   = proxyDestination.Port;
                uriBuilder.Scheme = Uri.UriSchemeHttps;
                base.Logger.Set(HttpProxyMetadata.RoutingHint, "RpcHttpProxyRules");
                this.updateRpcServer = false;
                return(new UrlAnchorMailbox(uriBuilder.Uri, this));
            }
            return(this.ResolveToDefaultAnchorMailbox(this.rpcServerTarget, "UnknownServerName"));
        }